Reputation: 11
I would like to setup the batch file is fit for different user. So I try to make the batch file a bit easier, then I use "set path" in the batch file, after I run, nothing is copy. Please instruct
And the Code that I'm using is:
@echo off
Set path=%source%;"C:\Users\basex\"
echo f | xcopy /s /h /y "%source%\AppData\Roaming\Microsoft\Sticky Notes\StickyNotes.snt" "%source%\Desktop\BACKUP\backup testing"
pause
Upvotes: 1
Views: 700
Reputation: 49097
Open a command prompt window and execute in this window set
to get listed all predefined environment variables. You see in the list
PATH
... semicolon separated list of folders to search for executables and scripts.PATHEXT
... semicolon separated list of file extensions for executables and scripts.Those two environment variables are used to find %SystemRoot%\System32\xcopy.exe
on having entered in console or in a batch file just xcopy
without file extension and without path. SystemRoot
is another predefined environment variable.
By overwriting predefined PATH
with the two folder paths, Windows command processor can't find anymore xcopy.exe
in system folder of Windows.
The list contains also other useful environment variables like
USERNAME
... name of the current user account.USERPROFILE
... path to the profile directory of the current user account.APPDATA
... path to the application data directory of the current user account.Run in command prompt window also xcopy /?
to get displayed the help for this standard Windows console application which is not an internal command of Windows command processor cmd.exe
.
Your task can be done with a single command line:
@%SystemRoot%\System32\xcopy.exe "%APPDATA%\Microsoft\Sticky Notes\StickyNotes.snt" "%USERPROFILE%\Desktop\Backup\" /H /I /Q /R /Y >nul
This command line copies the file StickyNotes.snt
from Sticky Notes
application data directory of current user to a backup directory in desktop directory of the current user with creating automatically the entire directory structure to the backup directory if that would be necessary.
By the way: The desktop directory of a user should contain only shortcuts in my point of view, i.e. *.lnk files and not files and folders. I suggest to have the backup directory in user profile directory and have on desktop a shortcut to this backup directory for easy accessing it from Windows desktop.
The internal command copy
is usually used to copy a single file and not xcopy
, but there might be reasons for using xcopy
which I don't know.
Upvotes: 2