We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

File Moving Copying Automation

CUBLA1
CUBLA1 asked
on
Medium Priority
277 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?
Comment
Watch Question

Commented:
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.

Author

Commented:
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...
Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
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)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.