Discussion Locked

A batch file with Julian date

0 helpful
10 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hello,
I have NT4.0 SP6a server. I want to run a batch file at certine time everyday. This batch file will move a file to another location and make a zip file and add julian date at the end of file name.

For example.
There is a file at C:\test\lint.txt
And I want to move it to C:\Live\
and make a zip file and save it to C:\backup\
add julian date to end of file name, looks like lint361.zip (today's julian date is 361)

Thank you in advance.
Lint

10 replies

by joseph moore

Julian date - can't help you there. Unless there is a 3rd party tool that can list the Julian date, I can't think of how you could get that from a batch file.

But, I can help if using MM/DD/YYYY is acceptable.

Now, I am using the command line version of Winzip, called WZZIP. You can get it for free from the Winzip web site (it is an add-on to Winzip).

Ok, here is your BAT file (call it ARCHIVE.BAT):

@ECHO OFF
c:
cd \
cd test
c:\progra~1\winzip\wzzip.exe lint.zip lint.txt
for /f"tokens=1-4 delims=:/ " %%i in ('date /t') do rename lint.zip lint%%j%%k%%l.zip
move lint*.zip c:\backup
move lint.txt c:\live
EXIT

Ok, when you run that today, it will take lint.txt and make a ZIP file originally called lint.zip.
Ok, after that, the FOR statement will parse the DATE /T command (which gives you "Fri 12/27/2002" today), ignores the spaces and the / characters, and takes only the numbers -- 12, 27, 2002 -- and assigns each one to a variable. Then the renaming of the temp ZIP file happens. Renaming lint.zip to lint%%j%%k%%L.zip gives you a file called LINT12272002.ZIP when ran today.

Ok, then just move the ZIP file to c:\backup and move the txt file to c:\live.

That should do it.

hope this helps

by joseph moore

Ok. 2 things.
1) In the "for /f "tokens=1-4 delims=:/ " %%i in ('date /t') do rename lint.zip lint%%j%%k%%l.zip" line, the first variable I usually use is %%i (yes, the variables are case-sensitive). What that does is it assigns the first value to %%i. After that, variables are assigned sequentially, so %%j is next, etc. That is why I said to use "lint%%j%%k%%l.zip" to get lint12302002.zip, because %%j=12, %%k=30 and %%l=2002.

2) Your new tool sounds good. YOu can use that in the FOR statment like this:

for /f "tokens=1-4 delims=:/ " %%i in ('JDAY.EXE -D -4') do rename lint.zip lint%%i.zip

Since the output for JDAY.EXE -D -4 is "2364" then it will be assigned to the %%i variable.

So, give that a shot! Also, can you send me JDAY.EXE so I can look at it? Send me a private message.

Personally, I use the Window Resource Kit tool NOW.EXE to do this type of date stuff. NOW.EXE gives you "Tue Dec 31 11:36:30 2002". I use that output in a FOR statement for a security camera, to archive pictures every 5 seconds.

Glad to help.

by lintadsl

Thank you very much. Using your script, I figured out what I want to get. Your example helped me a lot!!!
Happy new year!!

by lintadsl

It would be nice to know what REXX can do for me. Could you please post more detail/resource on here or give me a web link to check?

by lintadsl

Joseph,
I just got a tool called JDAY which display julian date to output. Now, I am using this and trying to figure out how to get that output and put into filename. ??? when I execute it in dos, it displays julian date. If you want to see, letme know I will send it to you.

by lintadsl

One thing that I don't get it is where did you get lint%%j%%k%%l.zip I understand that assign month to j, date goes to k and year goes to l. but don't get it how brake down from output, originally "Mon 12/30/2002" this format.
using JDAY -D -4, output is "2364" which is exactly i want to put into file name. How can I do this in for statment?

by johngreer

To show you how simple it is to do what you want in REXX, you just say:

filename = "lint"Date('J')".zip"

I've been using REXX for many, many years, starting way back in VM, then TSO, then OS/2, now Windows.

Mike Colishaw of IBM invented it, so IBM's site is the best place to start reading about it:
http://www2.hursley.ibm.com/rexx/

I use Regina Rexx for Windows.
Here are two sites that talk about it:

http://www.labyrinth.net.au/~dbareis/regina.htm

http://wwwinfo.cern.ch/regina/Welcome.regina

Just yell if you want more info or if you need help.

John

by lintadsl

Thank you for the details. I found another way to do this.
I am for sure your way will work very well but I just need to do simple things. Happy new year!!!

This discussion is closed to new replies.