Page 1 of 1

Backup

Posted: 12 Nov 2012 08:01
by john924xps
I have followed all the advice you guys gave me. But my program still doesn't work... so I have given up all hope. This is the piece of code I need help with:

Code: Select all

@echo off
title Backup
color 0a
setlocal enableDelayedExplansion
:varset
cls
set location=
set destination=
set agree=
echo Enter a location and destination or simply type save
echo to add and create paths to inherit from.
set /p location=Location of file/folder:
if /i "%location%"=="save" (
set save=location
goto save)
set /p destination=Destination to copy to:
if /i "%destination%"=="save" goto save
echo.
echo Location: %location%
echo Destination: %destination%
echo Agree?
set /p agree=(yes/no):
if /i "%agree%"=="no" goto varset
if not exist "%destination%\BackupMainDir" md "%destination%\BackupMainDir"
set checknum=1

:checkfunc
if exist "%destination%\BackupMainDir\Backup %checknum%" (
set /a checknum=%checknum% + 1
goto checkfunc) else (
md "%destination%\BackupMainDir\Backup %checknum%"
xcopy "%location%\*.*" "%destination%\BackupMainDir\Backup %checknum%" /s /h /e /k /f /c 2>nul
xcopy "%location%.*" "%destination%\BackupMainDir\Backup %checknum%" /s /h /e /k /f /c 2>nul
pause
goto :eof)

:save
cls
set stringload=
set new=
if exist "%appdata%\BackupSaves.txt" (
echo How many strings do you want to load?
set /p stringload=::
cd "%appdata%"
//PROBLEM STARTS HERE
<BackupSaves.txt (
for /l %%G in (0,1,!stringload!) do (
set /p _save%%G=)))
cls
echo Select a variable to inherit or type "new" to create a new list...
set _save
echo.
set /p select=::
if /i "%select%"=="new" (
echo.
set /p new=New Address:
cd %appdata%
if not exist "BackupSaves.txt" (
echo %new% > "BackupSaves.txt") else (
echo %new% >> "BackupSaves.txt")) else (
if "%save%"=="location" (
set location=%select%) else (
set destination=%select%))
goto varset

Re: Backup

Posted: 12 Nov 2012 08:03
by john924xps
X

Re: Backup

Posted: 18 Nov 2012 21:41
by john924xps
Can anybody here please help? D:

Re: Backup

Posted: 18 Nov 2012 23:23
by foxidrive
Put pause commands in and see where it fails - you didn't say what it does or doesn't do.

Re: Backup

Posted: 19 Nov 2012 05:19
by Aacini

Code: Select all

setlocal enableDelayedExplansion
"ExpLansion"? This makes that all expansions that use ! will NOT work...

Code: Select all

goto save)
Where is the ":save)" label located? It does NOT exist (just ":save")... The same happen with "checkfunc" and "eof"

Code: Select all

set /a checknum=%checknum% + 1
This does NOT work for the reasons I explained at this post
Note that this line:

Code: Select all

set /p _save%%G=)))
does NOT close any previous block...
The same happen three times more.

--> Place closing parentheses in separated lines!!! ie:

Code: Select all

set /p _save%%G=
)))

Antonio

Re: Backup

Posted: 19 Nov 2012 06:15
by john924xps
Thanks, guys. And I have always assumed that we didn't have to use a colon in the goto command.... thanks anyways!

Re: Backup

Posted: 19 Nov 2012 09:20
by Aacini
The problem is NOT the colon, but the parentheses!

Code: Select all

goto save)
is wrong, UNLESS you have this label placed in other line:

Code: Select all

:save)
A general problem with your code is the place where you put closing parentheses!!!

On the other hand, you may use GOTO LABEL or GOTO :LABEL if you wish, they both are exactly the same...

Antonio