cd "D:\WWW\SEAP_P\Web\Sec.Seap.Application\prod\TSE\mailer_bin\sent"
echo y | del *.*
I want to delete all the files from sent directory,when i run the bat file.it delete all the file from my desktop.can i know what caused this?
first please choose your destination drive then set directory you want to delete. here is looks like
D:
cd "WWW\SEAP_P\Web\Sec.Seap.Application\prod\TSE\mailer_bin\sent"
echo y | del *.*
make sure D: without "
or
cd /d "D:\WWW\SEAP_P\Web\Sec.Seap.Application\prod\TSE\mailer_bin\sent"
echo y | del *.*
as suggested by #SomethingDark in comment (Thanks BTW),
Let me know if it works.
Related
I'm using the Windows Command Processor, (cmd.exe), to scan all the files in a server. My goal is to have a .txt file with name files and where they are located, (for a faster search).
This is my code:
P:
DIR *.* /P /Q /S > C:\Users\aperea01\eng.TXT
Z:
DIR *.* /P /Q /S > C:\Users\aperea01\CADUsers.TXT
R:
DIR *.* /P /Q /S > C:\Users\aperea01\eng_restricted.TXT
The batch-file commits its goal, but if I find a folder I have no access, the batch-file stops working. It does write and save the last found files but can't continue.
Is there a way to skip the Access denied error and continue scanning the server?
Thanks in advance.
P, Z and R are some of the mapped network drives in my PC.
(FOR /R "P:\" %G IN (.) DO #PUSHD %G && #DIR /Q & #POPD) >> "C:\Users\aperea01\eng.TXT"
This will iterate over all subfolders in P:\ and only run DIR /Q (standard listing with owner) if the command is able to PUSHD (change directory) into it. All the output is redirected to eng.TXT. Hopefully this will prevent the Access denied problem you faced, though I'm unable to replicate the scenario you described.
How to delete a folder in a batch file forcely ?
(Note- C:\Anything is a folder)
My code is:
#echo off
del C:\Anything
pause
But it's always asking-
Do you want to delete "C:\Anything" Y/N ?
I want that C:\Anything should delete with askimg for permision to do that !
Please help to optimize my problem !!!
Use the rd command to delete folders:
rd /s /q "C:\My Folder\"
/s: Deletes all files and folder from selected path.
/q: Suppress any message.
The official docs are here.
set backupDir="D:\db_backup"
rmdir /s /q %backupDir%
here /q will eliminate that confirmation question.
My objective is
Map a network folder
Find a file on per-determined date with specific registration number
Copy the file to a specific location
Here is my code:
set "folder="
set "date="
set "No="
set "fileName="
echo:
set /p folder=Please enter the folder name
echo:
set /p date=Please enter report date yyyymmdd =
echo:
set /p No=Please enter registration number =
echo:
net use Q: \\%folder%\d$\h
net use R: \\%folder%\d$\p
CD Q:\%date%\0\ | findstr /i %No% "*.*"
echo:
set /p fileName=Paste filename to resend =
echo:
copy %fileName% y:
echo:
echo Copy Complete
echo:
Here is the output:
Please enter the folder you want to connect/reconnect = 0714
Please enter report date yyyymm = 201407
Please enter registration number = 74471958
The command completed successfully.
The command completed successfully.
FINDSTR: Cannot open NTUSER.DAT
FINDSTR: Cannot open NTUSER.DAT.LOG
Paste filename to resend =
I am currently running the batch from D: and I have copy findstr.exe to the same folder from which the batch file is running.
Currently I am really out of ideas and hope someone can point me on a right directions.
Your problem is this:
CD Q:\%date%\0\ | findstr /i %No% "*.*"
The pipe | takes the output of the previous command and feeds it to the following command.
The output of a cdcommand is empty (or "the system can not find this path").
So this is not, what (I think) you need.
I think, you want to go to Q:\%date%\0\ and search there for files, that contain %no%.
To do this, use:
cd /d "Q:\%date%\0\"
findstr /i %No% "*.*"
You need the /d parameter with cd to change to another drive (or use pushd instead of cd)
The problem with needing findstr.exe depends on precisely how you are executing this batch. This executable should be in c:\windows\system32 and that directory should be in your path. I'd echo %path% and pursue it from there.
Next problem is %date%. This is a magic variable and contians the current date. It can be overridden by a set command, but if it's set to nothing as you have done in you code, then it will return the current system date in the current user's format.
AFAIAA, CD produces no output; it merely changes directory.
I suspect you are using cygwin which provides different definitions for some commands.
I have a follow bat command which will delete unnecessary files when i give respective file extension
#ECHO OFF
REM Change the path and the extension...
DEL /s /f /q "C:\Users\dell\Desktop\test\*.pdf"
DEL /s /f /q "C:\Users\dell\Desktop\test\*.csv"
ECHO Are you sure ? Press a key to continue.
PAUSE > NUL
ECHO Done
PAUSE
I am in need to insert specific sub-folder to delete along with files. Assume specific sub-folder name may be abc
Can any body help me on this how to insert "delete specific sub-folder"
Use the RD command to remove a (sub)directory. Since a directory may not be empty, you may want to add the /S switch to remove the entire directory tree. And since you are also going to use the command in a batch script, you may need the /Q switch as well, to avoid the confirmation prompt.
So add a command like this to your script:
RD /S /Q "C:\Users\dell\Desktop\test\Specific\Subfolder"
i want to create a batch file
#echo off
set /p name="Type folder name(s):
md %name%
cd p:\%name%
all lines work, but i cannot change the directiory to cd p:\%name% when i run the script
thank you.
You need cd /d to change to a directory on another drive:
cd /d p:\%name%