Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help renaming a file using VBS/WSH

Status
Not open for further replies.

jguy

IS-IT--Management
Nov 17, 2000
69
0
0
US
I'm by no means a programmer, but I'm trying to automate a process using a combination of VBS and Batch files. First I execute a FTP batch file named simply ftp.bat that goes out to a mainframe and downloads several .DAT files. That works great. Next, I have a vbs script(zipit.vbs) that "calls for" another batch file (zip.bat) if a user chooses "yes" on a message box, else it basically stops. Here's the script code for the message box and "calling for" the zip.bat (zip.bat uses the command line add-on for Winzip)

zipit.vbs:

dim choice
Dim WSHShell
choice = msgbox ("Are You Sure That You Want To ZIP All Files With A .DAT Extention From The C:\DOWNLOAD Directory???",vbyesnocancel,"Watch Out!!!I'm Going To ZIP UP ALL .DAT Files!")

if choice = 6 then
Set WSHShell = WScript.CreateObject("WScript.Shell")
' This will run the zip batch file on demand.
WSHShell.Run "zip.bat", 1, false
Set WSHShell = Nothing
WScript.Quit(0)
end if

if choice = 7 then
msgbox "Not Going To ZIP At This Time!!!!",vbcritical,"No ZIP!"
end if

if choice = 2 then
msgbox "Canceling ZIP Operation!!!!",vbcritical,"Cancel This Operation!!!!"
end if


O.k., with this in mind, here's the simple zip.bat

syntax:wzzip -yp -b z:\dayendstring *.dat
rename z:\dayendstring.zip "%DATE%".zip

All of the above works fine. You'll notice that z: drive is on our network, this is where I'm going to store these zip files for archives. This actually puts the zip out there with the name dayendstring.zip. I want to somehow rename the dayendstring.zip to a date.zip (in other words 08/01/01 is what I mean by date) I know that Windows/DOS etc. doesn't like "/" in the file names, that's why the rename command in the batch file doesn't work. However, I know that "-" do work, but am uncertain how to do that from this point on. Could someone pls help me figure this one out??? Thank you so much in advance!!!
Joe W. Guy
Network Admin
MIS Director
 
jguy,

This should work.

fengshui1998

src = "C:\folder\yourfile.txt"
dd = Day(date)
mm = Month(date)
yy = Year(date)
strMonth = MonthName(mm, true)

Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile src, "C:\folder\" & dd & "-" & strMonth & "-" & yy & ".bat"
 
If wzzip is callable in your OS, then a possible scheme is as follows.

if choice = 6 then
Set WSHShell = WScript.CreateObject("WScript.Shell")
Dim fdate
fdate=DatePart("yyyy",now) & "-" & DatePart("m",now) & "-" & DatePart("d",now)
WSHShell.Run "wzzip - yp - b z:\" & fdate & ".zip" & " z:\*.dat",1,False
WScript.Quit()
end if

(I have supposed the *.dat are in z:\, if not, append the appropriate path there.)

This would produce the 2001-8-15.zip in your z:\ directly. (With appropriate modification, you can choose the format of date as will.)

If wzzip is not callable directly in your OS environment, then either you have to append cmd or command in front of wzzip line.

In any case, the idea is to avoid to make use of the environment variable %DATE% directly if you lack or avoid to take control over it.
 
tsuji,
Wow!! Thanks! It works! I words can't express my gratitude for the help! Again, thank you so much!

Joe Joe W. Guy
Network Admin
MIS Director
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top