Page 1 of 1

Specific Multiple delete

Posted: 16 Jan 2023 20:28
by xiro
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 :(

Re: Specific Multiple delete

Posted: 17 Jan 2023 06:08
by Lucky4Me
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 ,

Re: Specific Multiple delete

Posted: 17 Jan 2023 13:39
by Compo
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"

Re: Specific Multiple delete

Posted: 29 Jan 2023 18:53
by xiro
Thank you soooooooo much :)

It helps

Re: Specific Multiple delete

Posted: 29 Jan 2023 19:22
by xiro
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 :)

Re: Specific Multiple delete

Posted: 02 Feb 2023 20:31
by Compo
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.

Re: Specific Multiple delete

Posted: 03 Feb 2023 01:49
by xiro
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 :)