My question concerns a script I'm writing to automatically back up several Folders and subfolders with a batch file.
Now I'm trying to implement some kind of progress indicator in a readable format, preferably in per cent.
First of all, it reads the total size to copy with the following command:
FOR /R "C:\Users\XXX" %%F IN (*.*) DO (
set /a overall=!overall!+%%~zF
)
For the specific folder in my testing batch, this returns a size of 266,173,879 Bytes.
However, if I try to divide this number by, say, 1024 (for Kilobytes) after the for-loop with
set /a overall=%overall%/1024
the Batch returns something along the lines of "/1024 can not be used here syntactically" (You probably know the correct translation, mine is in German).
I tried adding/removing parantheses and spaces, but I keep getting the same error.
Is there something wrong with my syntax, which I'm too blindfolded to see?
If not, how do you call a C++ .exe delivering the value of %overall% to be assigned to a C++ variable?
(C++ is the only other programming language I have minimal to basic knowledge of, PowerShell is not an option, it has to be regular Windows Batch)
complete code of relevance:
FOR /R "C:\Users\XXX" %%F IN (*.*) DO (
set /a overall=!overall!+%%~zF
)
set /a overall=%overall%/1024
FOR /R "C:\Users\XXX" %%F IN (*.*) DO (
xcopy "%%F" "E:%%~pF" %parameter%>nul
cls
echo Copying... Progress: !size! of !overall! KB copied.
)
Here is some good info about Batch files and their math limitations. The page also has some information on how to best deal with these limitations.
There is a severe limitation in batch math: it can only handle 32-bit integers.
http://www.robvanderwoude.com/battech_math.php
Which is 4,294,967,295 for unsigned, −2,147,483,648 to 2,147,483,647 for signed.
For simplicity, you may just want to look into using robocopy
if you are using Windows 2003/XP or newer. Note that you must install the Windows Resource Pack (Works on XP) to add the robocopy tool. See the robocopy link for all the features and logging options.