Login | |
|
 |
Re: renaming a *.txt file with currentdate - 8/17/2001 2:43:29 PM
|
|
 |
|
| |
AndrewZ@dzimmer.com
Posts: 4
Score: 0
Joined: 8/16/2001
From: USA
Status: offline
|
It might be more than you need but I created a script that would move a file from one folder to another. It checked to see if the file already existed. If it does, it added a letter to it. I use it in a form that is passed the location of the existing file. 'Splits the file path into an array FILEARRAY = split(Request.Form("filename"), "\") 'Sets the root location. FOLDERPATH = "d:\inetpub\wwwroot\_private\forms\" & FILEARRAY(0) 'Checks if the folder exists where it will write the file. if FSOFILE.FolderExists(FOLDERPATH & "\archive") = FALSE then 'Creates the folder if it is not there. set FORMFOLDER = FSOFILE.CreateFolder(FOLDERPATH & "\archive") end if 'Gets the current Date. ARCHIVEDATE = Year(Now) & "-" & Day(Now) & "-" & Month(Now) 'Creates the file i.e. 'TestFile<ARCHIVEDATE>.txt' ARCHIVEFILENAME = Left(FILEARRAY(1), Len(FILEARRAY(1)) - 4) & ARCHIVEDATE & Right(FILEARRAY(1), 4) 'Sets the ANSI Character code for 'a' COUNTER = 97 BACKUPOK = 0 'Starts looping through the files in the folder checking to see if they exist. do while BACKUPOK = 0 'Checks if the First File Exists if FSOFILE.FileExists(FOLDERPATH & "\archive\" & ARCHIVEFILENAME) then 'If the file exists, it appends a letter to the end of the file name. It looks like I set it up to append 2 characters if one set it used up. x, y, z, za, zb, if COUNTER > 97 then ARCHIVEFILENAME = Left(ARCHIVEFILENAME, Len(ARCHIVEFILENAME) - 5) & Chr(COUNTER) & Right(ARCHIVEFILENAME, 4) else ARCHIVEFILENAME = Left(ARCHIVEFILENAME, Len(ARCHIVEFILENAME) - 4) & Chr(COUNTER) & Right(ARCHIVEFILENAME, 4) end if COUNTER = COUNTER + 1 else 'Copies the file to the new folder with the new name. set BACKUPFILE = FSOFILE.CopyFile(FOLDERPATH & "\" & FILEARRAY(1), FOLDERPATH & "\archive\" & ARCHIVEFILENAME, TRUE) 'Deletes the File set BACKUPFILE = FSOFILE.DeleteFile(FOLDERPATH & "\" & FILEARRAY(1)) end if loop
|
|
| |
|
|
|
 |
Re: renaming a *.txt file with currentdate - 8/17/2001 5:53:37 PM
|
|
 |
|
| |
imav8n
Posts: 95
Score: 0
Joined: 7/3/2001
From: USA
Status: offline
|
This is what I use for renaming and moving the log files on some of my servers to an archive folder. I'm actually using some other scripts that take the text files, and zip them up into a file called logfiles.zip, then moving that file to the archive. It's actually a combination of batch files and vbs files: StartHere.bat: ------------------------------------- del *.dt date /t > date.dt call dt.vbs FOR /F "TOKENS=1" %%A IN (dt.dt) DO CALL rn.bat %%A ------------------------------------------ - The first line deletes the previous *.dt files. - The 2nd line outputs the date into a new date.dt file in the "Thu 05/03/2001" format - The 3rd line calls dt.vbs code for which is below. This file creates a dt.dt file which has the date converted to 05-03-2001 format. - The 4th line takes the reformatted date from the dt.dt file, and puts it through a renaming batch file called rn.bat. Code is below. dt.vbs ------------------------------------------ Set objFileSystem = wscript.CreateObject( "Scripting.FileSystemObject" ) Set objFilez = objFileSystem.createTextFile("e:\logs\sec\pcs\dt.dt", true) Set objFilea = objFileSystem.OpenTextFile("e:\logs\sec\pcs\date.dt") Do While Not objfilea.AtEndOfStream scantext = ObjFilea.ReadLine st = right(scantext, 11) dt = trim(st) mo = left(dt, 2) da = mid(dt, 4,2) yr = right(dt,4) objfilez.writeline mo &"-"& da &"-"& yr loop ------------------------------------------ ------------------------------------------ rn.bat -------------------------------------- ren logfiles.zip %1.zip move %1.zip f:\archives\logs\sec\ -------------------------------------- Hopefully this helps, or at least gives you some ideas for how to do something similar. ~imav8n
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|