I need a Windows command to delete a directory and all its containing files but I do not want to see any errors if the directory does not exist.
Right click the bad file and click Add to Archives. Then in the options select to delete original file after compression. Leave other options same and proceed. Bad file will be deleted and a compressed file will be created in its place.
To do this, start by opening the Start menu (Windows key), typing run, and hitting Enter. In the dialogue that appears, type cmd and hit Enter again. With the command prompt open, enter del /f filename, where filename is the name of the file or files (you can specify multiple files using commas) you want to delete.
Use the rmdir command to remove the directory, specified by the Directory parameter, from the system. The directory must be empty (it can contain only .
Redirect the output of the del
command to nul. Note the 2
, to indicate error output should be redirected. See also this question, and especially the tech doc Using command redirection operators.
del {whateveroptions} 2>null
Or you can check for file existence before calling del
:
if exist c:\folder\file del c:\folder\file
Note that you can use if exist c:\folder\
(with the trailing \
) to check if c:\folder
is indeed a folder and not a file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With