Bala M
asked on
how to write Batch script to delete multiple files from different location/folders at a same time
Hello all,
I am trying to write a batch script to delete multiple files(different file types like .sta, .stw, .txt , .pdf, .docx , .ppt) located in different location by mentioning file paths in separate file.
But the script is not running and also not displaying any error.Anyone please help me to resolve this issue.
Used below script to delete files:
@echo off
for /f "tokens=*" %%a in (filelist.txt) do (
Echo Attempting to delete file %%a
Echo Del "D:\%%a"
)
content inside filelist.txt :
D:\Test\testing\testing1\t esting.ppt x
D:\Test\testing\testing1\t est2.docx
D:\test2\trial\trialref\re f1.xlsx
I am trying to write a batch script to delete multiple files(different file types like .sta, .stw, .txt , .pdf, .docx , .ppt) located in different location by mentioning file paths in separate file.
But the script is not running and also not displaying any error.Anyone please help me to resolve this issue.
Used below script to delete files:
@echo off
for /f "tokens=*" %%a in (filelist.txt) do (
Echo Attempting to delete file %%a
Echo Del "D:\%%a"
)
content inside filelist.txt :
D:\Test\testing\testing1\t
D:\Test\testing\testing1\t
D:\test2\trial\trialref\re
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Empty folders are nested within many folders.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Empty folders are deleted using above script.
Thank you Bill!!
Thank you Bill!!
ASKER
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello Bill,
Thank you for your help.I replaced all special characters into batch script acceptable format and tried to run the script.
Its working fine now without any issues.
I executed below command in command prompt to check how the special characters are visible in text file.
for %X in (a-acc:á e-acc:é i-acc:í o-acc:ó u-acc:ú u:uml:ü n-til:ñ) do (@echo:%X) >> international.txt
It executed the attached file (international.txt)
And then replaced those special characters in batch file with respective format as in international.txt file and its works fine now.
Thank you!!
international.txt
Thank you for your help.I replaced all special characters into batch script acceptable format and tried to run the script.
Its working fine now without any issues.
I executed below command in command prompt to check how the special characters are visible in text file.
for %X in (a-acc:á e-acc:é i-acc:í o-acc:ó u-acc:ú u:uml:ü n-til:ñ) do (@echo:%X) >> international.txt
It executed the attached file (international.txt)
And then replaced those special characters in batch file with respective format as in international.txt file and its works fine now.
Thank you!!
international.txt
ASKER
Thankyou for your help :)
Welcome.
»bp
»bp
ASKER
Thanks for your answers.I just removed the echo before del statement in script mentioned by oBdA ,as you people said and it works fine now.
I have a doubt,whether this works for files having special characters in their names?
For example, some of my files are having special characters such as ° é % â ç µ etc.. Because these didn't work in "xcopy" command earlier.So I took backup for those files manually earlier.Whether will it work on DELETE command?
And also can you please tell me how to delete empty folders in specified location.(But I dont know the folder names which are empty).
Thank you !!!