0

i want to make an auto backup script for my office. i've do some research and finally get some light bulb, but the problem is that my code just work in Windows 7 and won't work in Windows XP. so how do i solve this?
Here is my code

echo off
setlocal enabledelayedexpansion
:FIND.BACKUP.DRIVE.LETTER
set start.dir=%systemdrive%
J:
%cls%
if not "%cd:~0,2%"=="%start.dir%" goto next
I:
%cls%
if not "%cd:~0,2%"=="%start.dir%" goto next
H:
%cls%
if not "%cd:~0,2%"=="%start.dir%" goto next
G:
%cls%
if not "%cd:~0,2%"=="%start.dir%" goto next


if "%cd:~0,2%"=="%start.dir%" (
echo WAITING FOR FLASH MEDIUM TO BE CONNECTED . . .
if exist "%windir%\system32\timeout.exe" timeout /t 1 /nobreak >nul
if not exist "%windir%\system32\timeout.exe" pause
goto FIND.FLASH.DRIVE.LETTER
)

:next
set start.hour=%time:~0,2%
set start.min=%time:~3,2%

REM FLASH.DRIVE IS THE FLASH DRIVE.
set flash.drive=%cd:~0,2%

set date="%date:~7,2%-%date:~4,2%-%date:~10,4%"
mkdir "%userprofile%\desktop\a\%date%"

xcopy "%flash.drive%\*.*" /s /c /d /e /h /i /r /y %userprofile%\desktop\a\%date%

if not exist %flash.drive% set /a total.time=((((%time:~0,2%-%start.hour%)... && echo Flash Drive has been in for !total.time! minutes. && Pause>nul
@pause

thanks

DannyBoi
  • 636
  • 1
  • 7
  • 23
uniks
  • 59
  • 8
  • 1. The `won't work` phrase has no diagnostic value: please [edit] your question and specify what comes wrong; 2. Use `echo ON` to see what happen exactly; 3. Don't use `set date=...` and so on for [_volatile_ environment variables](http://ss64.com/nt/syntax-variables.html): use another name e.g. `set _date=...` – JosefZ Aug 13 '15 at 06:00
  • 1
    You have a label `FIND.BACKUP.DRIVE.LETTER` at top of batch file, but do a __goto__ to `FIND.FLASH.DRIVE.LETTER`, i.e. `BACKUP` versus `FLASH`. Further I suggest to avoid everywhere a dot in labels and environment variables and use CamelCase notation, i.e. `FindFlashDriveLetter` and `StartDir`. There are also references of environment variable `cls` not defined anywhere in batch code. Don't use `cls` as variable name to avoid confusion with command __cls__ (clear screen). A replace for `timeout` is using __ping__, see [How to wait in a batch script?](http://stackoverflow.com/questions/735285/) – Mofi Aug 13 '15 at 06:08

1 Answers1

1

This should be reliable, to do the same task.

Are you sure that you need the /d switch in xcopy?

@echo off
:loop
echo waiting... Please insert the flash drive...
ping -n 3 "" >nul
set "drv="
for %%a in (g h i j) do if exist "%%a:\" set "drv=%%a:"
if not defined drv goto :loop

REM drv IS THE FLASH DRIVE.

set start.hour=%time:~0,2%
set start.min=%time:~3,2%
set "d8=%date:~7,2%-%date:~4,2%-%date:~10,4%"

xcopy "%drv%\*.*" /s /c /d /e /h /r /y "%userprofile%\desktop\a\%d8%\"

set end.hour=%time:~0,2%
set end.min=%time:~3,2%
pause

I believe your calculation of total time is broken, and is something that you can work on.

foxidrive
  • 40,353
  • 10
  • 53
  • 68