Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
xiro
- Posts: 34
- Joined: 21 May 2014 00:17
#1
Post
by xiro » 16 Jan 2023 20:28
This works
del C:\Users\MLM\Downloads\TEST DEL *.zip *.txt *.doc *.jpg *.exe *.pdf /q /f
but when I put the same command on another pc it says the Path could not be found
del "E:\PC1-HOME\export\corrupted\*.*" /q planning to modify it for a specific file to be deleted so I make something like this
del "E:\PC1-HOME\export\corrupted\*.xml *.zip" /q not working I tried to remove the \
del "E:\PC1-HOME\export\corrupted *.xml *.zip" /q
File could not be found......... Wht is wrong with this command it is OK in one PC then error on the other PC

-
Lucky4Me
- Posts: 29
- Joined: 21 Oct 2020 06:33
#2
Post
by Lucky4Me » 17 Jan 2023 06:08
try this one
Code: Select all
for /r "YOUR DRIVE AND MAP" %%g in (*.xml,*.zip) do (del /q /f %%g)
change YOUR DRIVE AND MAP into "E:\PC1-HOME\export\corrupted" and adjust the extensions you want to delete. Seperate extensions with a ,
-
Compo
- Posts: 600
- Joined: 21 Mar 2014 08:50
#3
Post
by Compo » 17 Jan 2023 13:39
Try to change to the directory first:
Code: Select all
CD /D "E:\PC1-HOME\export\corrupted" && (
Del /F /Q *.xml *.zip
)
Or:
Code: Select all
CD /D "E:\PC1-HOME\export\corrupted"
If ErrorLevel 0 Del /F /Q *.xml *.zip
Or:
Code: Select all
CD /D "E:\PC1-HOME\export\corrupted"
If %ErrorLevel% Equ 0 Del /F /Q *.xml *.zip
Or:
Code: Select all
PushD "E:\PC1-HOME\export\corrupted" && (
Del /F /Q *.xml *.zip
PopD
)
Or:
Code: Select all
PushD "E:\PC1-HOME\export\corrupted"
If ErrorLevel 0 (
Del /F /Q *.xml *.zip
PopD
)
Or:
Code: Select all
PushD "E:\PC1-HOME\export\corrupted"
If %ErrorLevel% Equ 0 (
Del /F /Q *.xml *.zip
PopD
)
Alternatively, use the absolute paths:
Code: Select all
Del /F /Q "E:\PC1-HOME\export\corrupted\*.xml" "E:\PC1-HOME\export\corrupted\*.zip"
-
xiro
- Posts: 34
- Joined: 21 May 2014 00:17
#4
Post
by xiro » 29 Jan 2023 18:53
Thank you soooooooo much
It helps
-
xiro
- Posts: 34
- Joined: 21 May 2014 00:17
#5
Post
by xiro » 29 Jan 2023 19:22
gathered all your ideas I was able to construct something like this
cd /d "PC-1\J\export\corrupted\"
Del *.xml *.zip *.rar *.contact *.rtf *.rar
cls
pause
Thank you so much for your help

-
Compo
- Posts: 600
- Joined: 21 Mar 2014 08:50
#6
Post
by Compo » 02 Feb 2023 20:31
xiro wrote: ↑29 Jan 2023 19:22
cd /d "PC-1\J\export\corrupted\"
Del *.xml *.zip *.rar *.contact *.rtf *.rar
cls
pause
Why, did you not use the code I gave you?
Not only are you likely to get an error message, because you're trying to delete all .rar files after you've already delated them, but you've made a grave mistake too. If the directory change to PC-1\J\export\corrupted fails in any way, the next line is going to permanently delete all files in whatever remains as the current directory. Other than using the CD command with the /D option, you've learned absolutely nothing from what I posted in more than two weeks of me submitting it.
-
xiro
- Posts: 34
- Joined: 21 May 2014 00:17
#7
Post
by xiro » 03 Feb 2023 01:49
Compo wrote: ↑02 Feb 2023 20:31
xiro wrote: ↑29 Jan 2023 19:22
cd /d "PC-1\J\export\corrupted\"
Del *.xml *.zip *.rar *.contact *.rtf *.rar
cls
pause
Why, did you not use the code I gave you?
Not only are you likely to get an error message, because you're trying to delete all .rar files after you've already delated them, but you've made a grave mistake too. If the directory change to PC-1\J\export\corrupted fails in any way, the next line is going to permanently delete all files in whatever remains as the current directory. Other than using the CD command with the /D option, you've learned absolutely nothing from what I posted in more than two weeks of me submitting it.
Yes, I have noticed that for the unfortunate event, it could delete all in the directory if it could not find its intended path. Regarding the .rar just encoded it twice. For your could I have derived it to make it somewhat simple but all the given code snippets were saved by me to be used for a bigger project.
Thank you so much for your effort for giving me the sample code I just used the simple one so easy to trace the error in the script I have created
