Batch File Commands

Its been longer than I realized since I had to wrtie an decent batch file script. The one I need is a bit more robust than I'm used to. Can someone give me some ideas on the commands and syntax to write a batch file that will move a group of files from one directory to another series of directories based on a identifier in the name... I need the resulting dispersed files the retain their file level names, but create a folder in the destination directory that is named based on the date of the move. I need empty zip files to be deleted and logging in case there are errors. I need an email or report sent to me if this process fails... Please assist.
Noah WilliamsNetwork EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
For the first part, which is the move part, there are a couple of ways you could approach that.  Depending on the identifier location and format in the file name, you might just be able to do several MOVE commands, like this:

SET InputDir=c:\temp
SET OutputDir=d:\backup
SET Today=%Date:~-4,4%%Date:~-10,2%%Date:~-7,2%
MD "%OutputDir%\%Today%"
MOVE "%InputDir%\*pat1*.*" "%OutputDir%\%Today%"
MOVE "%InputDir%\*pat2*.*" "%OutputDir%\%Today%"
MOVE "%InputDir%\*pat3*.*" "%OutputDir%\%Today%"

For the ZIP empty file detection, what ZIP tool are you using?

As far as the logging and error reporting, you will have to think about what constitutes an "error".  Are you just looking for trapping if the actual MOVE command fails, or are there other things you want to check for, like the existence of the input and output folders, etc.  If so then code needs to be added to check those things and log errors of found.

The most common way to send email from a BAT script is with BLAT, which you can search for here on EE and find some examples of.  There are a couple of alternatives as well, like SENDMAIL.

~bp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Noah WilliamsNetwork EngineerAuthor Commented:
We are using unzip command Win 2008 R2. (Do you suggest any?)
An error should be reported if a move isn't successful, e.g. no source file found or problems with input and output folders. A simple log that can be checked later for troubleshooting. We will set the process to repeat several times a day to capture these files to move.
I need a trigger in the script to send an email on any of these conditions.
~nw
Bill PrewIT / Software Engineering ConsultantCommented:
So what are the file name patterns you are looking for, and what directories do they go it?

Are you saying that if you look for a file name pattern and no files exist matching, then that is a fatal error condition?

~bp
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Noah WilliamsNetwork EngineerAuthor Commented:
The filenames are (date)POBOX(po box #). zip and we need them to go to directories named by the PO Box #... I would want it to log no file name pattern matching, but I wouldn't want the routine to stop or cause a fatal error...
So, I think the answer is yes, but I only want to log if a condition is met... Then, email me.
~nw
Bill PrewIT / Software Engineering ConsultantCommented:
Can you share some real life examples of the actual files names?

~bp
Noah WilliamsNetwork EngineerAuthor Commented:
Sure:
20100930POBOX105329.zip.pgp
GMCFOUTPUTCOUNTS20100930.txt
These are samples of files I want to move to other directories. One directory for the text file counts. Another directory on a server that needs a batch file running to unPGP the zips with GnuPG Shell v1.0 and then unZIP them using windows unzip to their final destinations according to PO Box...
Thank you.
~nw
Bill PrewIT / Software Engineering ConsultantCommented:
Okay, so both these files would be in the same source directory?

And then what directories do you want these files copied to, and what should the files be named in those directories?

~bp
Noah WilliamsNetwork EngineerAuthor Commented:
Source Directory: \\sourcecorpserver\sourcecorp
20100930POBOX105329.zip.pgp copies to \\Taskmaster\archive
GMCFOUTPUTCOUNTS20100930.txt copies to \\Taskmaster\text
A command should create a folder in the \\Taskmaster\archive directory based on the current date. All the 20100930POBOX105329.zip.pgp  files will then be copied in this dated folder per day.
A command will be run using GnuPG Shell v1.0 to unPGP, then to unZIP the files from the dated folders per day to specific PO Box share folders per day per PO BOX, i.e. \\shareserver\POBOX105329 (there are 5 PO Boxes...
~nw
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Installation

From novice to tech pro — start learning today.