1

Below is the script.I am copying files based on date given by user.

@echo off
echo Enter Date in mm-dd-yyyy:
set /p dt= 
echo %dt%

if %dt% =="" goto :EnterDate


if not %dt% =="" goto :CopyFile

:CopyFile
xcopy C:\Users\hkum29\Desktop\Source\*.* C:\Users\hkum29\Desktop\Destination\*.* /d:%dt%

:EnterDate
echo Enter Date

Pause
lit
  • 14,456
  • 10
  • 65
  • 119
Hemant Kumar
  • 39
  • 1
  • 2

2 Answers2

1

IF syntax is if string1 operator string2 action

If string1 or string2 is "quoted" (which allows a string to contain spaces) then BOTH strings must be quoted.

Batch has no concept of "sections", "functions", "procedures" or "paragraphs". A label is simply a reference point. Execution does not stop when a label is reached, it simply continues through, line by line, until it reaches end-of-file, a CALL , a GOTO or an EXIT

Magoo
  • 77,302
  • 8
  • 62
  • 84
0

Think that Script logic should be

@echo off 
SetLocal
:EnterDate
set /p dt="Enter Date in mm-dd-yyyy: " 
if "%dt%" == "" goto :EnterDate

:CopyFile
echo %dt%
xcopy C:\Users\hkum29\Desktop\Source\*.* C:\Users\hkum29\Desktop\Destination\*.* /d:%dt%
EndLocal
Pause

You should better add date validation Batch Script: Validate Date Input

You may also validate it using a very ugly trick, (for it abuses the system date)

@echo off 
SetLocal
:EnterDate
set /p dt="Enter Date in mm-dd-yyyy: " 
if "%dt%" == "" goto :EnterDate

set "saved_date=%date%"
echo %dt%|DATE >NUL 2>&1 && (
  echo %saved_date%|DATE >NUL 2>&1
) || (
  echo %saved_date%|DATE >NUL 2>&1 
  echo %dt% is not a valid date
  goto :EnterDate
)

:CopyFile
echo %dt%
echo xcopy C:\Users\hkum29\Desktop\Source\*.* C:\Users\hkum29\Desktop\Destination\*.* /d:%dt%
EndLocal
Pause

exit/B
elzooilogico
  • 1,659
  • 2
  • 17
  • 18
  • Using `mm-dd-yyyy` only works on systems in locales such as en_US. Using `robocopy` might be a better choice. – lit May 25 '17 at 12:53