Reputation: 27592
I want to create a simple batch script which:
A
to the current directory (which also contains some files) An straight-forward solution is to loop through all the files inside A
, copy them and keep a list of them. Then clean-up at the end.
But I'm wondering if there is a better solution.
Upvotes: 0
Views: 96
Reputation: 41234
@echo off
copy "c:\A\*.*" .
rem run commands
for %%a in ("c:\a\*.*") do del "%%~nxa"
Upvotes: 1
Reputation: 67216
@echo off
attrib +R *.*
copy \A\*.*
rem run commands
del *.*
attrib -R *.*
Of course, this method works only if the commands does NOT modify anyone of the original files, but it is faster and also prevents to overwrite anyone of the original files.
Upvotes: 0
Reputation: 37569
@echo off &setlocal
set "folder=%userprofile%\A"
set "dirlist=my dirlist.txt"
dir /b "%folder%" > "%dirlist%"
copy "%folder%"
rem doit here
for /f "usebackq delims=" %%a in ("%dirlist%") do erase "%%~a"
It belongs to you to care for duplicate files.
Upvotes: 0
Reputation: 103467
Save a list of the files, copy them, do your stuff, then delete using your list:
dir /b A >list.txt
copy A\*.* .
rem do stuff here
for /F "delims=" %%i in (list.txt) do del %%i
del list.txt
Upvotes: 0