Good evening all,
Please excuse the basic question - I'm attempting to create a script to make some jobs at my workplace a little more efficient.
The script is designed to open a network share and create a folder within, ask for input from the user (which will be the local profile name), and if it exists, copy the contents to the folder we created on the network share. The script will then remove the network share.
The script is as follows (excuse the untidiness)
@echo off
net use X: \\40aGlenwood-NAS\ROOM16-Backup
:UserInput
set /p "UserName=Enter the user's name: "
IF NOT EXIST %UserName% GOTO UserInput
IF EXIST %UserName% GOTO Proceed
:Proceed
xcopy "C:\Users\%UserName%\Desktop" "X:\Backup" /f /r /i
net use X: /D /YES
timeout /t 10
This script works well in theory, however once run, the command box displays the following:
"Douglas" is not recognized as an internal or external command
See, the word 'Douglas' is part of the variable that we have declared. It isn't supposed to be a command.
Any help here? I know it's not the affecting the script, however I don't want it to display that message. Also, bear in mind that I have no previous experience coding or creating batch scripts.
UserNameis a predefined environment var already set with current users name. If you want to refer to the current user no need to ask. You aren't creating a dir in the code. To check the existence of a dir you'll need to include the path (and better double quote it)cmdwindow:IF NOT EXIST Joe Douglas echo GOTO UserInput. Use double quotes:IF NOT EXIST "Joe Douglas" echo GOTO UserInput.