Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
kunaljadhav
- Posts: 2
- Joined: 28 Oct 2015 06:29
#1
Post
by kunaljadhav » 28 Oct 2015 06:43
Hello,
I am trying to create a batch file which will take back up of my folders in destination location in date wise folder.
But when I try to run the commands in sequence one by one in cmd it works as per requirement but if I try to collect all commands in batch file it gives error.
I am using date as a variable to create folder in destination location and there the problem in my syntax.
Please see below batch for details and let me know suitable solution for this.
Code: Select all
@echo off
Rem Change the directory to take backup as required below and also update the sourse location as required
set Source=C:\TEMP\INPUT\TEST
set destination=C:\TEMP\OUTPUT
for /f "tokens=1-5 delims=/ " %d in ("%date%") do set Today=%e-%f-%g /n
echo %Today%
mkdir %destination%\%Today%
xcopy %Source% %destination%\%Today% /e /i /h
Best regards
Kunal Jadhav
Last edited by
Squashman on 28 Oct 2015 06:48, edited 1 time in total.
Reason: MOD EDIT: Please use CODE TAGS.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 28 Oct 2015 06:47
From the FOR command help file.
Code: Select all
To use the FOR command in a batch program, specify %%variable instead
of %variable. Variable names are case sensitive, so %i is different
from %I.
-
kunaljadhav
- Posts: 2
- Joined: 28 Oct 2015 06:29
#3
Post
by kunaljadhav » 28 Oct 2015 23:34
Thank you for reply.
But I was using the command in similar command before but was giving me error as below
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do set Today=%%e-%%f-%%g
%%d was unexpected at this time.
So I tried using single % and I went through.
Please note I want to create a batch file which will help to create folder with date and take backup of files.
Also I want to use this date variable to append same with time variable and create other folder depending upon current time and write files inside it.
Best regards
Kunal Jadhav
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#4
Post
by Squashman » 29 Oct 2015 07:31
kunaljadhav wrote:But I was using the command in similar command before but was giving me error as below
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do set Today=%%e-%%f-%%g
%%d was unexpected at this time.
So I tried using single % and I went through.
Correct. You cannot use two percent symbols when running the command from the cmd prompt. You can only use one. You use two when running from a batch file. The help file seems pretty clear so I am not sure what you are still having problems with.