Solved

File Moving Copying Automation

Posted on 2006-10-28
6
253 Views
Last Modified: 2010-04-16
We have users storing simple word documents into their respective F:\example\userfolder with this format CLIENT-PERSONNAME-DATE-OURUSER.DOC I want a script of some type .bat maybe? Suggestions? That can run at a given time of day that will do a variety of things with these files:

First the script would copy all docs based on each "ouruser" criteria to a seperate folder path like x:\example\ouruser

Maybe something like this, except it would have to be able to search all folders within the F:\ for ouruser # in case someone screws up and drops it in the wrong directory:

COPY F:\*OURUSER1.* x:\example\ouruser1 (how do i get it to search all folders?)
COPY F:\*OURUSER2.* x:\example\ouruser2
ETC...

Second the script would copy all docs based on "personname" criteria to seperate folder path like z:\example\personname during this action the script would also copy certain "personname" docs to a y:\toprint folder so a person on our staff would know to print them.

Rough Example:

COPY F:\*PERSONNAME.* z:\example\personname IF personname EQUALS blah also COPY F:\example\toprint

Problem is the EQUALS list would be rather long? How do I handle that?

somewhere in there or at the end the script I will need to delete all files in the F:\example\userfolder after performing all the above actions, and this has to work flawlessly...haha...

Now, my question is, how to write this? What scripting language? Where do I start and would a simple .bat file work? Currently we are manually moving all files and managing the folders and it's killing us. The filenames are set and exact so that is our one constant. We are running all Windows 2003 Standard Servers with XP machines.

Ideas?
0
Comment
Question by:CUBLA1
  • 3
6 Comments
 
LVL 1

Expert Comment

by:Aristo
ID: 17827270
Hello CUBLA1,

Although it can be done by vbscript, it also can be done using batch:

First you should use xcopy and not copy, so instead of:
COPY F:\*OURUSER1.* x:\example\ouruser1
use:
XCOPY F:\*OURUSER1.* x:\example\ouruser1 /S
(/S will go inside subdirs)

The second problem is depend on what you are looking for, if you need a batch parameter you can use the %1 like this
COPY F:\*%1.* z:\example\%1
If your batch is called x.bat then you will run:
x personname
and the %1 will be replaced with personname.

The if condition should be like this
if "%1" == "Person1"  COPY F:\*%1.* F:\example\toprint

on the delete you can use the del /Q for quiet deletion (without yes/no).

I hope this will give you a start, or you can always goto to the vbscript and FileSystemObject for manipulating files based on strings.

Bu if you can use batch it is my prefered way of solving such issues.
0
 

Author Comment

by:CUBLA1
ID: 17827626
good start for sure. i think it will be fun to get this batch working correctly. However, your response brings more questions. should i have multiple batch files for each person name or can it all be done with one bat? seems to me it would be 1 bat otherwise i would be defeating the purpose? Also, i've used xcopy alot in the past so that i'm familiar with. the second and third part of your message however i'm lost. i understand the wildcard of %1...you basically say if it equals this do this and so on...but how do you build that list? also i'm confused with the "if your batch is called x.bat then you will run: x personname"

so roughly this is where I am:

@echo off
XCOPY F:\*OURUSER1.* x:\example\ouruser1 /s
XCOPY F:\*OURUSER2.* x:\example\ouruser2 /s
XCOPY F:\*OURUSER3.* x:\example\ouruser3 /s
(etc)
XCOPY F:\*%1.* z:\example\%1 /s

IF "%1" ="PERSONNAME1" COPY F:\*%1.* y:\example\toprint /s (needs to search all directories)

My Idea (tell me whats wrong) Can I simply do this:

XCOPY F:\*PERSONNAME1.* z:\example\PERSONNAME1 /s
XCOPY F:\*PERSONNAME2.* z:\example\PERSONNAME2 /s
(etc)

IF "PERSONNAME1" = "BLAH" COPY y:\example\toprint

(then to end)

DEL F:\OURUSER1\*.* /q
DEL F:\OURUSER2\*.* /q
DEL F:\OURUSER3\*.* /q
(etc)

Or is there a way to tell it to del all files on F:\ inside any subfolder but leave the folders?

thanks for your help...
0
 
LVL 1

Accepted Solution

by:
Aristo earned 500 total points
ID: 17830297
Ok,

You have raised some good questions.
You could go with your solution with just one change at the end:
DEL F:\OURUSER3\*.* /q/s
The /s will delete files inside subfolders, but will not delete the folders.

You colud split the batch making it more generic:

file:UserProcess.bat
@echo off
XCOPY F:\*%1.* z:\example\%1 /s

IF %1 = "BLAH" COPY y:\example\toprint
IF %1 = "BLAH2" COPY y:\example\toprint

DEL F:\%1\*.* /q/s

file:main.bat
call UserProcess.bat PERSONNAME1
call UserProcess.bat PERSONNAME2

That way, if you need to add or remove persons, you will have only to change it in the main.bat.

Hope this helps you.

0
 
LVL 1

Expert Comment

by:Aristo
ID: 17836514
I have a better idea for files split:
file:UserProcess.bat
@echo off
XCOPY F:\*%1.* z:\example\%1 /s

IF %2 = "y" COPY y:\example\toprint

DEL F:\%1\*.* /q/s

file:main.bat
call UserProcess.bat PERSONNAME1 y
(This will copy to y:\example\toprint)
call UserProcess.bat PERSONNAME2
(This will not copy to y:\example\toprint)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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

20 Experts available now in Live!

Get 1:1 Help Now