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

NewbieKid
  • 87
  • 7
  • 1
    Open a [command prompt](https://www.howtogeek.com/235101/), 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`. – Mofi Oct 17 '20 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?](https://stackoverflow.com/a/49834019/3074564) – Mofi Oct 17 '20 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](https://stackoverflow.com/help/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? – Mofi Oct 17 '20 at 10:25
  • @Mofi I solved it! I just remove the option `/D` and `/E`. – NewbieKid Oct 18 '20 at 22:55

1 Answers1

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.

Wasif
  • 14,755
  • 3
  • 14
  • 34