Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete files from a list?

Tags:

xcopy

I have a filesystem that uses a hash algorithm to organize files. I have used xcopy in the past to copy files to a different location by passing in a file that has a list of all the files and having it iterate through it. The script looks similar to the following:

for /f "delims=, tokens=1,2,3" %i in (D:\foo.csv) 
do echo F | xcopy /i /d "Z:\%i\%j\%k" "Y:\%i\%j\%k" >> "D:\xcopy\Log.txt"

However, now I've run into a situation where in addition to copying the files that are provided in the foo.csv file, I want them to be deleted as well. I looked at the xcopy documentation and couldn't find anything. Is there someway I can accomplish this, even if I have to run another script to go through the same list of files and delete them after using xcopy?

Thanks!

like image 600
Saggio Avatar asked Oct 10 '22 19:10

Saggio


1 Answers

You can use parenthesis to indicate multiple commands to be excecuted by the for operand:

for /f "delims=, tokens=1,2,3" %%i in (D:\foo.csv) do (
    echo F | xcopy /i /d "Z:\%%i\%%j\%%k" "Y:\%%i\%%j\%%k" >> "D:\xcopy\Log.txt"
    del /F "Z:\%%i\%%j\%%k"
)
like image 192
yms Avatar answered Oct 13 '22 11:10

yms