Solved

File Moving Copying Automation

Posted on 2006-10-28
6
255 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

821 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