Link to home
Start Free TrialLog in
Avatar of Bala M
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\testing.pptx
D:\Test\testing\testing1\test2.docx
D:\test2\trial\trialref\ref1.xlsx
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bala M
Bala M

ASKER

Hello oBdA and Bill Prew,

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 !!!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bala M

ASKER

Empty folders are nested within many folders.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bala M

ASKER

Empty folders are deleted using above script.
Thank you Bill!!
Avatar of Bala M

ASKER

I had mentioned the file names within double quotes in "filelist.txt" as below

        "D:\trial\çxxx\%%%percentile\âtryspl\spl char.txt"

User generated image
But I got the error as in above attached screenshot.Even i tried only by mentioning file name within double quotes,but it didn't work.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bala M

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
Avatar of Bala M

ASKER

Thankyou for your help :)
Welcome.


»bp