Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

File Moving Copying Automation

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
CUBLA1
Asked:
CUBLA1
  • 3
1 Solution
 
AristoCommented:
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
 
CUBLA1Author 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...
0
 
AristoCommented:
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
 
AristoCommented:
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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now