Solved

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

Posted on 2010-11-10
9
508 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 51

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
When it comes to security, there are always trade-offs between security and convenience/ease of administration. This article examines some of the main pros and cons of using key authentication vs password authentication for hosting an SFTP server.
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

11 Experts available now in Live!

Get 1:1 Help Now