@echo on
set src=c:\test
set dst=d:\test
xcopy %src% %dst%
for /F "TOKENS=*" %%G in ('dir/b ^%src%\*.*^') DO set new=%%G
attrib +h "%dst%\%new%"
del "%dst%"
attrib -h "%dst%\%new%"
pause
Source:
file1
file2
Destination:
file3
The only problem I have is that I don’t know why only file2 is read in the for loop which adds the attribute h to the file. I want all the files under the Source folder to be added the assigned attribute.
How could I fix that?
You get what you typed 🙂
You can debug a batch file simply by removing the
@echo off.Your loop process all files, and set the
newvariable, but theattrib +hand the rest is executed after the loop, not inside.And I assume you want to hide first all files which exists in the src folder, then delete the rest, and then unhide all files.
But this block can’t work, as it hides one file deletes all the others and then unhides the file again.
You could try this instead, it hides all necessary files, delete then the other files, and unhides all files.