|
Answer» I am trying to make a simple batch file that will copy jpgs to a flash drive, renaming each jpg in a numerical COUNT (1.jpg, 2.jpg, 3.jpg, etc) and log the corresponding number with original location/filenames to a log (list.txt)
Here is my code: Code: [Select]set num=0
mkdir "%~d0\HIDDEN\%computername%"
set targetfolder=%~d0\hidden\%computername% ECHO %computername% > %targetfolder%\list.txt
d: for /f "delims==" %%F in ('dir /s /b *.jpg') do ( set num=%num%+1 xcopy "%%F" "%targetfolder%\%num%.jpg" /s/c/q/r/h ECHO %num% %%F >> %targetfolder%\list.txt )
@pause @cls @exit
However, it seems to ignore my handles for the xcopy command. It also seems to ignore adding one onto the variable 'num' on each loop.
What am I doing wrong?Variables set within a for loop require special handling:
Code: [Select]setlocal enabledelayedexpansion set num=0
mkdir "%~d0\hidden\%computername%"
set targetfolder=%~d0\hidden\%computername% ECHO %computername% > %targetfolder%\list.txt
d: for /f "delims==" %%F in ('dir /s /b *.jpg') do ( call set /a num=%%num%%+1 xcopy "%%F" "%targetfolder%\!num!.jpg" /s/c/q/r/h ECHO %num% %%F >> %targetfolder%\list.txt )
@pause @cls
Sidewinder: STILL does not increase num. CONTINUALLY tries to write to file 0.jpg each time.I guess I missed the one on the echo statement. The XCOPY should have been fine. Not for nothing but what OS are you using?
Code: [Select]setlocal enabledelayedexpansion set num=0
mkdir "%~d0\hidden\%computername%"
set targetfolder=%~d0\hidden\%computername% ECHO %computername% > %targetfolder%\list.txt
d: for /f "delims==" %%F in ('dir /s /b *.jpg') do ( call set /a num=%%num%%+1 xcopy "%%F" "%targetfolder%\!num!.jpg" /s/c/q/r/h ECHO !num! %%F >> %targetfolder%\list.txt )
@pause @cls
I'm using XP Pro SP2
I tried simplifying the count for now, creating a new batch file with only that FOR loop ECHOing the value of num, then adding to num, then ECHOing num again. When I use ! in place of %, it literally outputs "!num!" instead of it's value, but it is still not adding to num's value.Are you using the setlocal statement? I'm still unable to duplicate your results.
Sorry, that was a stupid typo on my part. The counting variable is working just fine now.
However, the xcopy command is apparently ignoring the handles I have sent to it, so it is asking whether each and every file copied is a File or a Directory. That doesn't make for a very automated process.Quote xcopy command is apparently ignoring the handles I have sent to it
Do not understand the terminology.
Try piping the XCOPY response:
echo D | xcopy "%%F" "%targetfolder%\!num!.jpg" /s/c/q/r/h
OR
echo F | xcopy "%%F" "%targetfolder%\!num!.jpg" /s/c/q/r/h
You might want to double check if those are the proper responses. Sorry, to clarify: Xcopy is ignoring the handles/options/attributes I'm trying to send it with the source and destination: "/s/c/q/r/h"
which tells it to search subfolders, continue even if there are errors, do not display filename while copying, overwrite read-only files, and to copy hidden and system files; respectively
|