0

When the script gets to the IF statement, it just ends. It doesn't go to the next line which is pause for debugging.

set yymm=%DATE:~12,2%%DATE:~4,2%
set DD=%DATE:~7,2%
robocopy "\\client system\Users\login name\Videos" "F:\Temporary\Videos\Process\New Batch\%yymm%%dd%\Netbook\Videos" /mir
set /p %user%=Did Netbook Videos complete? (y/n): 
IF %user%=="y" (del "\\client system\Users\login name\Videos\"*.* /s/q) ELSE (echo Skipping)

I know that there is a /move switch for robocopy command. But it tells me that it doesn't have access to the destination folder. The batch program runs with administrative access and it is running in the profile that created the folder. So I wrote a workaround.

Why is this happening?

Mofi
  • 38,783
  • 14
  • 62
  • 115
  • 2
    2 issues, 1st `set /p %user%=` will input to the variable referenced by the **content** not the variable uesr so => `set /p user=` 2nd the if would only be true if the input was `"y"` Both sides of a comparison have to be quoted. –  Nov 23 '18 at 02:24
  • 1
    You do not use percent symbols with the variable name when using the `SET` command. You only use the percent symbols when you need to access the value of the variable. IF commands are literal comparisons. If you have quotes on one side of the comparison they must be on the other side for the comparison to be true. – Squashman Nov 23 '18 at 02:27
  • @LotPings Thank you. I've removed the quotes from the set variable and added the second comparison, with no change in behaviour. `set yymm=%DATE:~12,2%%DATE:~4,2% set DD=%DATE:~7,2% robocopy "\\client system\Users\login name\Videos" "F:\Temporary\Videos\Process\New Batch\%yymm%%dd%\Netbook\Videos" /mir set /p %user%=Did Netbook Videos complete? (y/n): IF %user%=="y" (del "\\client system\Users\login name\Videos"*.* /s/q) ELSE if %user%=="n" (echo Skipping)` Sorry, the character returns aren't appearing... – Ben Bowring Nov 23 '18 at 03:42
  • @Squashman ^^^^ – Ben Bowring Nov 23 '18 at 03:43
  • 2
    @BenBowring do not put that much code in a comment. Lotpings and I basically said the same thing and the code in your comment does not address either of the two changes we suggested. – Squashman Nov 23 '18 at 03:47
  • Something did not save correctly. It works now because of the `%` signs I used in the `set` command. However, there is no need to do a second if check for the `else` statement as this site explains: https://www.tutorialspoint.com/batch_script/batch_script_if_else_statement.htm – Ben Bowring Nov 23 '18 at 03:50
  • @BenBowring, neither of us told you to use a second `IF` statement. – Squashman Nov 23 '18 at 03:58

1 Answers1

0

I recommend first to read following answers:

The batch file below assumes that the string substitutions done with value of dynamic environment variable DATE works with used user account because of date format depends on which region/country/locale is set for used user account.

set "yymm=%DATE:~12,2%%DATE:~4,2%"
set "DD=%DATE:~7,2%"
%SystemRoot%\System32\robocopy.exe "\\client system\Users\login name\Videos" "F:\Temporary\Videos\Process\New Batch\%yymm%%dd%\Netbook\Videos" /mir
%SystemRoot%\System32\choice.exe /N /M "Did Netbook Videos complete? (y/n): "
if errorlevel 2 (echo Skipping) else del /S /Q "\\client system\Users\login name\Videos\*"

I suggest also reading How to delete files/subfolders in a specific directory at command prompt in Windows? The command DEL as used here does not delete all files and leaves behind subdirectories which are most likely empty after deleting most or by chance all video files. But it would be good to avoid deletion of hidden system file desktop.ini in videos directory of a user account which is usually referenced with %USERPROFILE%\Videos.

For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.

  • choice /?
  • del /?
  • echo /?
  • if /?
  • robocopy /?
  • set /?
Mofi
  • 38,783
  • 14
  • 62
  • 115