Question:
Batch file Read, Write, and Variable?
2011-12-13 02:04:36 UTC
I'm writing a batch file for backing up a folder. Now everything is working except one thing. I would like it to have a count on how many backups it does. So i would like to have a txt file that has a number in it that increases by 1 each time it backups. This is the code i have for the counting by one;

cd c:\users\duncan\documents\test\
set /p count= %count% = %count% + 1
%count%>c:\users\duncan\documents\test\count.txt

Please would somebody be able to show me how to code it so it will work.
Three answers:
Jake
2011-12-13 09:32:39 UTC
echo off

cd c:\users\duncan\documents\test\

if not exist count.txt set count=0

if exist count.txt set /p count=
set /a count= %count% + 1

echo %count% >count.txt



the "set /a..." command indicates that you want to add two numbers.
brisray
2011-12-13 05:09:37 UTC
Use Robocopy.



It will tell you the number of directories searched, the number of files checked, the number of bytes those files contained. For each of those it will tell you how many were skipped, mismatched or failed, as well the as the speed of the transfer and how long the backup took.



http://technet.microsoft.com/en-us/library/cc733145(WS.10).aspx



Robocopy has been part of the DOS utilities since Windows 2000.



To increment a counter you need to use set /a - that is if you're using it as an environmental variable.



This may help you...



http://stackoverflow.com/questions/5248393/windows-batch-file-to-copy-and-keep-duplicates

http://www.robvanderwoude.com/shorts.php



To write the variable to a file you need to echo it



echo %count% > c:\users...



depending on what you are trying to do you sometimes have to append the count



echo %count% >> c:\users...
MrAlex6204
2011-12-13 07:12:42 UTC
why you don't use VBScript *.vbs

is more easy an you can run it from prompt and vbs has more function

like run the script in the startup write and read files create,delete,rename folders or file



you cant use if,while make variables, get the special path folders of the current system or use InputBox to get a info from the user like in visual Basic



Is easy to write like this example



'Write this code in notepad and save as hello.vbs after save go to the file

'and do doubleclick on it,

'Find more information of vbs in google



msgbox("Hello world")


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...