I’m trying to write a batch file that is basically used for copying destinations. Now, I want to make it to where other people can use it without having to go in and edit the directories and destinations. Is there a way for me to write the batch file to where it prompts, asking for the directory the user would like to copy, and to ask for the drive that the user would like to copy it to?
This is what I’ve been using for a while now.
@echo off
:: variable
set backupdir="Destination"
set backupcmd=xcopy /e /h /f /y /v /c /i /r /g /k /d
echo.
echo +++ Backing Up Data +++
echo.
echo.
%backupcmd% "Directory\*.*" "%backupdir%\Data"
timeout /t 2
cls
echo Backup Complete
echo.
echo.
timeout /t 2
cls
echo.
echo +++ Now taking hidden and system attributes off of folders +++
echo.
echo.
echo.
attrib -s -h "Destination\Data"
echo.
echo.
timeout /t 3
And is there any way that I can improve this with using xcopy?
You could use:
From the docs:
You use it like:
And:
Then change your copy command to:
And don’t forget your
attribcommand (which should have already been using%backupdir%):As an alternative, consider allowing optional command line arguments:
Implemented with these changes:
Finally, adding a
SETLOCALline after@echo offwill keep your named variables out of the global environment space.