• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 520
  • Last Modified:

How to create a windows batch file to archive users files in XP?

Hi,

Can you tell me how to write a windows batch file script to archive a user or users files in XP?


Many thanks
Sandy.
0
sweetiepie70
Asked:
sweetiepie70
2 Solutions
 
jasonabarnettCommented:
Hi Sandy,

Let's assume the users files are stored in a location called C:\Files.

Let's also assume you want to archive them to a network drive called F:\Archive.

Let's assume you want a unique Archive folder for each user too.

I'd do something like the attached.

Regards,

Jason
REM check if F: is mapped and if so disconnect it
if exist F:\ net use F: /d

REM map F: to \\myserver\myshare
net use F: \\myserver\myshare

REM check if archive folder exists and if not then create it
if not exist F:\Archive\%username% mkdir F:\Archive\%username%

REM copy user data to archive folder
xcopy /E /R /Y /C C:\File F:\Archive\%username%

REM disconnect network drive
net use F: /d

Open in new window

0
 
sweetiepie70Author Commented:
Jason,

Many thanks for this.  I was wondering if there was a simpler way to achieve this.


Sandy
0
 
Bill PrewCommented:
Can you be any more specific about what you are looking for?  Is this something you will run on the actual computer where the user files exist, or remotely?  What types of files or information are you looking to save?  And where do you want to save it, to the same PC, or to a network location, etc?

~bp
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
sweetiepie70Author Commented:
Hi BP,

I would like to save it on say an external drive or usb drive from the c drive on a computer or laptop.  The files will be on that computer or laptop but will be archived to an external drive/usb drive.


Regards
Sandy
0
 
justadadCommented:
The above batch file could be shortened quite a bit, however he put in some nice checks on if something exists. The biggest problem about doing it to an external drive will also be in the launching of the batch file to know what the destination drive letter is.

One way to do this would be to place the batch file on the removable media and run it from there, but you have to do some fancy foot work to get the path.
So it would be something like this:

Replace F:\ with %~dp0

That will get around determining where to copy the files to.

One last thing and that is the xcopy will always copy all of the files. You could add a /d which would only copy newer files. But again that will not delete any files that have been removed. This is not truly an archive as any new file will overwrite the old.  To get around these limitations you would need to install a tool such as robocopy or 7zip and call them from the cmd file.
REM copy user data to archive folder
xcopy /E /R /Y /C /D C:\File %~dp0Archive\%username%

Open in new window

0
 
BillDLCommented:
Just for your info, and is not intended to divert from the excellent advice and suggestions above.  You may be interested in a little free program named "Shadow Copy" http://www.runtime.org/shadow-copy.htm).
It provides a simple user interface to copy directories, and overcomes the problem of files currently in use not being copied. It does this by using the Windows Volume Shadow Copy Service. It can be run from the command line also.
0
 
Here2HelpCommented:
Hey.

Try 'Sync'.
http://syncdir.sourceforge.net/

Copy Sync.jar and Sync.bat (from the windows folder in the zip file) to a folder and call it Sync.  Sync.bat will need to be edited so open it up in to notepad.

If you supply specific information such as the exact folder path you want to archive.  Whether overwriting matching files shud be allowed or just rename matching names on-the-fly.  Also any file types that shouldn't be included for archive then me and the experts can put it together for you.
0
 
Richard QuadlingSenior Software DeverloperCommented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now