Solved

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

Posted on 2010-11-10
9
509 Views
Last Modified: 2013-12-24
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
Comment
Question by:sweetiepie70
9 Comments
 

Accepted Solution

by:
jasonabarnett earned 125 total points
ID: 34106367
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
 

Author Comment

by:sweetiepie70
ID: 34106672
Jason,

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


Sandy
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 34107158
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
 

Author Comment

by:sweetiepie70
ID: 34107269
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 7

Assisted Solution

by:justadad
justadad earned 125 total points
ID: 34109294
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
 
LVL 38

Expert Comment

by:BillDL
ID: 34183142
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
 
LVL 8

Expert Comment

by:Here2Help
ID: 34362583
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
 
LVL 40

Expert Comment

by:RQuadling
ID: 34626701
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

Give your grad a cloud of their own!

With up to 8TB of storage, give your favorite graduate their own personal cloud to centralize all their photos, videos and music in one safe place. They can save, sync and share all their stuff, and automatic photo backup helps free up space on their smartphone and tablet.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If your business is like most, chances are you still need to maintain a fax infrastructure for your staff. It’s hard to believe that a communication technology that was thriving in the mid-80s could still be an essential part of your team’s modern I…
PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now