Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Batch file copy cmds not working correctly.

08 Jan 2019   #11
SnakeFist

Windows 7 Ultimate x64 SP1
 
 

Quote   Quote: Originally Posted by dg1261 View Post
For troubleshooting purposes, temporarily precede the "%backupcmd% ..." lines in the 4 and 5 subsections with "echo %backupcmd% ..." This will tell the script to echo on screen what command it's designed to perform, in lieu of actually trying to perform it.

This can be system-dependent, but on my system it reveals subsection 4 is trying to execute:
xcopy /s /r /y /k /v /e /i "C:\Users\Dan\AppData\Roaming\Local" "F:\Save Game Files\Goes Back To AppData Folder"

while subsection 5 is trying to execute:
xcopy /s /r /y /k /v /e /i "C:\Users\Dan\AppData\Roaming\Roaming" "F:\Save Game Files\Goes Back To AppData Roaming Folder"

Obviously, these commands are only going to work if these folders exist:
"C:\Users\Dan\AppData\Roaming\Local"
"F:\Save Game Files\Goes Back To AppData Folder"
"C:\Users\Dan\AppData\Roaming\Roaming"
"F:\Save Game Files\Goes Back To AppData Roaming Folder"
The two C: folder locations look particularly suspicious to me. Check your system to see if Roaming\Local and Roaming\Roaming actually exist. They don't on mine ... hence, the error messages.

Looking at your script, I see those subsections are drawing part of the filespec from %AppData%, so that's where you're probably running into trouble. You need to modify that or use something else.


Technical aside: your filespec in subsection 4 finishes with "Local", but you're not telling the OS whether that refers to a file or a folder. If there's a folder named "Local" at "C:\Users\Dan\AppData\Roaming" it will correctly guess you want all the files in the "Local" folder, but if there's no such folder there, it will assume you must be referring to a file named "Local" at that location.

Since my system has neither a file nor a folder called "Local" in "C:\Users\Dan\AppData\Roaming", the OS is assuming your script is referring to a file and hence the "File not found - Local" error message.

The same goes for subsection 5.
I'm trying to back up C:\Users\Your user name here\AppData\Local and C:\Users\your username here\AppData\roaming folders. Where it says your user name here will be the persons user name like in your case you have Dan. I'm sure all windows 7, 8 and 10 has this location.

I thought i had to use %appdata%\local to point to C:\Users\Your user name here\AppData\Local .
Same with the appdata\roaming folder.

There is no Roaming\Local or Roaming\Roaming.


My System SpecsSystem Spec
.
08 Jan 2019   #12
dg1261

Windows 7/8.1/10 multiboot
 
 

You can see all the environment variables by opening a command-prompt window and typing "set".

I'm not sure, but I think %appdata% may universally be the ..\appdata\roaming folder and %localappdata% may universally be ..\appdata\local. You might try changing your script from %appdata%\Local to %localappdata%, and %appdata%\roaming to just %appdata%.

If that doesn't work, you could probably change them to %userprofile%\appdata\local and %userprofile%\appdata\roaming.
My System SpecsSystem Spec
12 Jan 2019   #13
SnakeFist

Windows 7 Ultimate x64 SP1
 
 

Quote   Quote: Originally Posted by dg1261 View Post
You can see all the environment variables by opening a command-prompt window and typing "set".

I'm not sure, but I think %appdata% may universally be the ..\appdata\roaming folder and %localappdata% may universally be ..\appdata\local. You might try changing your script from %appdata%\Local to %localappdata%, and %appdata%\roaming to just %appdata%.

If that doesn't work, you could probably change them to %userprofile%\appdata\local and %userprofile%\appdata\roaming.
Ok everything is working great. Thank you.

Now is there a command that will let me store the backup folder in the same folder as the batch file?
My System SpecsSystem Spec
.

12 Jan 2019   #14
dg1261

Windows 7/8.1/10 multiboot
 
 

Quote   Quote: Originally Posted by SnakeFist View Post
Now is there a command that will let me store the backup folder in the same folder as the batch file?
Well, in assorted places your batch file sets an environment variable per "set drive=F:\Saved Game Files\(etc)..." and then uses that env var in the backup command. So what you need to do somehow is dynamically change that "set drive=" command based on where the batch file is being called from.

You can probably get close to what you want by tinkering with the %cd% env var*, which represents the "current directory". For instance, open a command-prompt window and switch to the F:\ directory, and "echo %cd%" should return "F:\". Switch to the "F:\Saved Game Files" directory, and "echo %cd%" should return "F:\Saved Game Files". So wherever you put your batch file, change its relevant commands to "set drive=%cd%\..." and go from there.

Just keep in mind that there are a few scenarios where this may not get you want you want. It depends on how you call your batch file.

For instance, if you have "mybatchfile.bat" in F:\, it should work properly if you open F:\ in an Explorer window and double-click "mybatchfile.bat". (The %cd% embedded in your batch file should expand to "F:\".)

In contrast, it will fail if you open a command-prompt window to somewhere else (like "C:\users\me\desktop") and type "f:\mybatchfile". In that case, f:\mybatchfile.bat will still run but the embedded %cd% will expand to "C:\users\me\desktop".

It's not the end of the world, but just understand there are limits to where and how the %cd% variable can be used.


* You'll find a comprehensive list of environment variables here.
My System SpecsSystem Spec
12 Jan 2019   #15
SnakeFist

Windows 7 Ultimate x64 SP1
 
 

Quote   Quote: Originally Posted by dg1261 View Post
Well, in assorted places your batch file sets an environment variable per "set drive=F:\Saved Game Files\(etc)..." and then uses that env var in the backup command. So what you need to do somehow is dynamically change that "set drive=" command based on where the batch file is being called from.

You can probably get close to what you want by tinkering with the %cd% env var*, which represents the "current directory". For instance, open a command-prompt window and switch to the F:\ directory, and "echo %cd%" should return "F:\". Switch to the "F:\Saved Game Files" directory, and "echo %cd%" should return "F:\Saved Game Files". So wherever you put your batch file, change its relevant commands to "set drive=%cd%\..." and go from there.

Just keep in mind that there are a few scenarios where this may not get you want you want. It depends on how you call your batch file.

For instance, if you have "mybatchfile.bat" in F:\, it should work properly if you open F:\ in an Explorer window and double-click "mybatchfile.bat". (The %cd% embedded in your batch file should expand to "F:\".)

In contrast, it will fail if you open a command-prompt window to somewhere else (like "C:\users\me\desktop") and type "f:\mybatchfile". In that case, f:\mybatchfile.bat will still run but the embedded %cd% will expand to "C:\users\me\desktop".

It's not the end of the world, but just understand there are limits to where and how the %cd% variable can be used.


* You'll find a comprehensive list of environment variables here.
Thanks. I'll try it out and do some testing and see how it goes.
My System SpecsSystem Spec
15 Jan 2019   #16
SnakeFist

Windows 7 Ultimate x64 SP1
 
 

Hey it works as expected. I even reversed the commands to make it to be able to restore the files back to where they was.
How i tested it was i backed up my data using the batch file and installed vm virtual machine installed the programs to make the paths where the data will goes. Which is steam and ubisoft the rest is default in windows.
It restored the data back to where it belongs.
Deleted my host data and use guest os data in vm and it backed up very nicely.
Thank you for helping me. I have added to your rep.
My System SpecsSystem Spec
15 Jan 2019   #17
dg1261

Windows 7/8.1/10 multiboot
 
 

That's good to hear. Thanks for posting back and letting us know how it turned out.
My System SpecsSystem Spec
15 Jan 2019   #18
SnakeFist

Windows 7 Ultimate x64 SP1
 
 

Quote   Quote: Originally Posted by dg1261 View Post
That's good to hear. Thanks for posting back and letting us know how it turned out.
Your Welcome.
My System SpecsSystem Spec
Reply

 Batch file copy cmds not working correctly.




Thread Tools




Similar help and support threads
Thread Forum
Batch File .bat to copy file from File Sharing & FTP Hosting
Hi all, Any idea how to write Batch File .bat to copy file from File Sharing & FTP Hosting to local directory. Current the File Sharing & FTP Hosting is SMARTFILE. I don't want to use WINSCP as the connector. Thanks
General Discussion
Unable to correctly parse lines in a .txt file through batch
Good Afternoon All, This is my first post so if I inadvertently insult anyone through my mannerism I apologize in advance. So the puzzle is that my company creates programs for our clients and would like me to create a batch file that can be placed on the desktop and auto-copy all of the...
General Discussion
Batch file to copy files from C drive to USB
Hi all, To increase our backup solutions, we have decided to backup our SQL database every hour to a folder within the C drive (we couldn't get it to backup straight to a USB drive). So now we need a way (batch file best solution?) to copy these files to the USB drive, lets say every 1.05hours...
Backup and Restore
Windows7 Batch File Copy Possible?
Fellow Forum Members, I have two external hard drives I'm calling Hard Drive A and Hard Drive B. Hard Drive A & B are mounted to external USB cradles. Both USB cradles are connected to the same PC containing Hard Drive C. My objective is to transfer all data files, folders, sub folders from both...
Performance & Maintenance
How to copy a file from 1 pc to another pc in network using batch file
Help me make a batch file that copies a file from one computer to another computer in a network... PC1 = Source PC2 = Destination I want to copy a file from PC1's Drive E: to PC2's Drive E:
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 02:34.
Twitter Facebook