So I am trying to make a batch file to sync an external hard drive.
My hard drive is not always connected to the same letter, so i cannot just make a batch file with xcopy F:\Folder1 G:\backupharddrive
because G:\backupharddrive
would be variable
Is there a way to just copy to the folder the batch file is in?
Just use relative addressing, where .
represents the current directory.
xcopy F:\Folder1 .
For future reference, you can also access the parent of the current folder (IOW, 1 level higher up in the directory tree) using ..
. This makes it handy to move up a level, or even over one. For instance, to copy files from C:\Temp\One
to C:\Temp\Two
, you can use
xcopy *.* ..\Two\
which means copy the files from this folder up one level and then over to the Two folder.
If you use dir
from a command prompt, you'll see that in any level below the drive root you'll have items for .
and ..
in the list. (The root only has .
, because it has no parent folder.