Computing.Net > Forums > Programming > Batch file W2K3: Create DIR w/date

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file W2K3: Create DIR w/date

Reply to Message Icon

Name: BMS
Date: February 9, 2006 at 08:09:44 Pacific
OS: W2K3 SERVER .NET
CPU/Ram: DUAL 3.4 / 2G
Product: DELL PE2800
Comment:

I did a quick search and could not find what I need. I have tried this on my own and came very close... but no cigar!

Here is my scenario: I have computer out in the shop that contains all the CNC programs we use daily in our manufacturing process. This computer up-loads and downloads these CNC files from each of several machine tools via hardwire and a port switcher. Several semi-qualified people send/receive these files daily, and they manage to "hose up" files constantly. I do a normal back up every night, but some times a file is corrupted and we don't know it until 6 months later. My back-ups normally only go back a maximum of 8 weeks.

I now have plenty of network storage available and would like to COPY (not BACKUP) the directory (about 35 MEG) once a week to a network folder. What I attempted to do was write a batch file to be run on my utility server as a scheduled task. What I want it to do is; create a DIR named as "today's date", and copy the source directory in its entirety, then close.

My last attempt would create the new Dir and name it properly, but then it copies the source directory to the root instead of the newly named DIR. I'm sure it is just an issue with me being "SYNTAX" challenged. The only way I ever get syntax right is copy/paste!!!

My utility server is running Windows Server 2003 .NET and the source machine is a Windows Advanced Server 2000.

Below is what I have that DOES work. This will create a new DIR and name it properly. What I can't seem to do is then make this newly created DIR the target to copy the files to.

I would appreciate any assistance with the second half of this batch file.

@echo off
R:
cd R:\MACHINE PROGRAMS
for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set var= %%A%%B%%C
md %var%
cd R:\MACHINE PROGRAMS\%var%\



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: February 9, 2006 at 12:38:46 Pacific
Reply:

Hi,

Well, you got close. Welcome to the local chapter of syntax challengers anonymous.

One definite snag:

set var= %%A%%B%%C

sets a var with a LEADING SPACE, which is probably not what you want.

One possible snag:

To CD to a dir with spaces, like "MACHINE PROGRAMS" it is always a good practice to use opening double quotes. I hedge my bet and use closing double quotes as well.

Try the bat below, substituting s: for r:

::== nc2.bat
for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set var=%%A%%B%%C
s:
md "s:\MACHINE PROGRAMS\%var%"
cd "s:\MACHINE PROGRAMS\%var%"
:: DONE



If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: BMS
Date: February 10, 2006 at 04:37:22 Pacific
Reply:

Mechanix2Go,

I don't know how much time you spent on this, but you saved me a ton of aggravation. I changed the drive letters, created a line with the xcopy info, added it to my Scheduled Tasks and it works PEFECTLY! This was a task that I have been doing, (supposed to be doing) manually for years. But I get busy, forgetful, or whatever and failed to it every week. Someday it was going to cause me a problem.

It is forums like this one, and people like you that are willing to share their knowledge that allow people like me to keep their IT jobs, when perhaps I should be mowing grass or washing dishes.

I seriously appreciate you help, THANKS!!


0

Response Number 3
Name: Mechanix2Go
Date: February 11, 2006 at 03:09:38 Pacific
Reply:

BMS,

Glad that helped.

Your not the only IT guy who's been helped by a shade tree mechanic. That's just how it is. The whole is greater than the sum of it's parts. We're a neural network.

It didn't take me much time to do your script. But it took thousands of hours to learn HOW to get the knots out. LOL

FWIW,

I always prefer the YYYYMMDD layout because it allows easier sorting.

Also, I worked in a shop where we used PCs as point of sale boxes and backed up to a server at least 4 times a day. I wrote a bat to "increment" the dir name; made it dead easy.

"semi-qualified people"

YER! At the university I worked for we always made things "student proof". Never did figure out how to make things "PhD proof".

;)


If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Countdown timer in VB6 Web/Client Temp Files



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file W2K3: Create DIR w/date

Batch file to list dir name www.computing.net/answers/programming/batch-file-to-list-dir-name-/17362.html

Batch File to Create a Shortcut www.computing.net/answers/programming/batch-file-to-create-a-shortcut/13374.html

Batch file to append created date www.computing.net/answers/programming/batch-file-to-append-created-date/14993.html