1

I have created a simple batch script that only copies pdf file in the server. Copied file will be stored in a folder in desktop.

But after copying there is a "New Folder" created. Why is this happening?

this is my script :

:MENU1
set /p code=Input Folder Code:
if %code%==0 goto MENU1
goto CHECK1

:CHECK1
if exist "%sample2020%\%code%\STANDARD\DATA\PLAN\%code%WAB.pdf goto COPYFILE
if not exist else goto ERROR

:COPYFILE
xcopy "%sample2020%\%code%\STANDARD\DATA\PLAN\%code%WAB.pdf" "%HOMEPATH%\Desktop\2. FILES\%code%\DOCUMENTS\" /D /E /C /I /Y /H

start "" "%HOMEPATH%\Desktop\2. FILES\%code%\DOCUMENTS\"
goto MENU1

:ERROR
echo.
echo PK file cannot find....
PAUSE
start "" "%HOMEPATH%\Desktop\2. FILES\%code%\DOCUMENTS\" 

this is the actual image of copied files ... as you can see it has a New Folder.. enter image description here

4
  • 1
    Open a command prompt, run if /? and read the output help. if not exist else goto ERROR is not of correct syntax. It can be replaced by just goto ERROR. Commented Oct 17, 2020 at 10:17
  • I recommend further to replace if %code%==0 goto MENU1 by if defined code if "%code:"=%" == "0" goto MENU1 for more safety against wrong user input by mistake. See the answer on How to stop Windows command interpreter from quitting batch file execution on an incorrect user input? Commented Oct 17, 2020 at 10:20
  • 1
    The only command creating a folder is xcopy and that does not create a New folder. But the batch is not a minimal, reproducible example. We don't know how the environment variable sample2020 is defined and we don't know what the user of this batch file enters. Why do yo use xcopy.exe instead of newer robocopy.exe? Why do you use xcopy option /D. Why do you use xcopy option /E to copy also empty directories if you want to copy only a PDF file. Why do you not use copy to copy a single PDF file? Commented Oct 17, 2020 at 10:25
  • @Mofi I solved it! I just remove the option /D and /E. Commented Oct 18, 2020 at 22:55

1 Answer 1

0

The "New folder" dosen't seem to be created by xcopy. Both folders Modification Date is different. Here your switches and other commands don't create any kind of directories. So it might be create by a different application.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for answering. I just remove the option /D and E. Now the New Folder gone..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.