Need to create a .bat to grab folders inside users folder

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DonnieNarco
Posts: 2
Joined: 21 Jun 2013 09:02

Need to create a .bat to grab folders inside users folder

#1 Post by DonnieNarco » 21 Jun 2013 09:18

Hey, I have been racking my brain and finally gave in...came here to see if anyone who is good with this can assist me.

I have Windows 7 machines that each contain multiple user profiles. Inside each of these profiles, there is the Favorites folder, as well as the Firefox folder inside AppData folder. My goal is to create a batch file that will go inside each of these users folder, grab a particular set of folders and then back them up to a central folder designated by me, all containing inside a new folder named with the user profiles name.

Then I plan to take the newly created folder with all of the users backed up files over to another computer, and easily be able to merge them with the current folders on the new PC.

Is there a batch file that can do this? I am not good at writing batch files at all, but I have been searching and searching for someone else who has already created one. The closest I found was a batch file that grabs Firefox profiles, but only under that user account logged in.
I am logging in as local admin, so I have access to all of the users profiles.

Can someone help me create one?

Here are the details of what I need:

( c:/users/**** = each user folder that is found within this users folder)

C:/Users/***/Favorites (Copy this entire folder)
C:/Users/***/AppData/Roaming/Mozilla/Firefox (Copy this entire folder)

Send the copied info over to a newly created folder located on the Desktop, possibly named "Users Backup"
This "User Backup" needs or should have a folder structure similar to the C:/Users folder so that it is easy to determine who has what information for restoration procedures.

-------------------

Then if possible, another batch file that would look at this folder and take the backed up information and puts it back in place on the other PC, but Merges the files, not overwrites them. If the same file already exists, it will overwrite it, but it wont overwrite the entire folder itself (otherwise favorites would be erased possibly)


I hope that someone can help me with this. I have been looking for a few weeks and I just can't find what I am looking for. I guess in that few weeks I could have already done a few of these PCs manually, but I have a lot to do.
Thanks in advance.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need to create a .bat to grab folders inside users folde

#2 Post by foxidrive » 21 Jun 2013 11:11

This might work. Test it well first.

It will also attempt to backup system accounts and will generate harmless errors when it can't find the folders.
You should delete the obviously stupid folders in the set "c:\Users Backup" prior to restoring.

If you replace the entire mozilla folder then less configuring is required. It should be plug and play and use the right profile. Any existing profile in a restored mozilla folder will remain, but will be unused.


Code: Select all

::backup
@echo off
set "target=c:\Users Backup"
for /f "delims=" %%a in (' dir c:\users /b /ad  ') do (
xcopy /s/h/e/k/f/c "c:\users\%%a\favourites\*.* "%target%\%%a\favourites\"
xcopy /s/h/e/k/f/c "c:\users\%%a\appdata\roaming\mozilla\*.* "%target%\%%a\appdata\roaming\mozilla\"
)


Code: Select all

::restore
@echo off
set "source=c:\Users Backup"
for /f "delims=" %%a in (' dir c:\users /b /ad  ') do (
xcopy /s/h/e/k/f/c/y "%source%\%%a\favourites\*.* "c:\users\%%a\favourites\"
xcopy /s/h/e/k/f/c/y "%source%\%%a\appdata\roaming\mozilla\*.* "c:\users\%%a\appdata\roaming\mozilla\"
)

DonnieNarco
Posts: 2
Joined: 21 Jun 2013 09:02

Re: Need to create a .bat to grab folders inside users folde

#3 Post by DonnieNarco » 21 Jun 2013 11:31

Thank you very much!!
I will try it out soon and report back if it works.

Post Reply