Re: Rename a file with yesterdays days date by Pegasus
Pegasus
Sat May 10 08:26:50 CDT 2008
"Danc383@hotmail.com" <Danc383hotmailcom@discussions.microsoft.com> wrote in
message news:C89BF2F7-2698-4079-A190-BAF1BFE7BAC4@microsoft.com...
> Hi,
>
> How can i rename a file (c\AutoDaily\18991230.zip) with yesterdays date.
> (c\AutoDaily\20080510.zip)
>
> Then move the file to:
> (c\AutoDaily\Archive\20080510.zip)
>
> Cheers
> Dan
>
You could use the script below. You need to be careful with your
file & folder names - I assume you did not mean
c\AutoDaily\20080510.zip but instead
c:\AutoDaily\20080510.zip
01. Const sWD = "c:\AutoDaily\"
02. Const sArchive = "c:\AutoDaily\Archive\"
03. Const sFName = "c:\AutoDaily\18991230.zip"
04.
05. Set oFSO = CreateObject("Scripting.FileSystemObject")
06. If Not oFSO.FolderExists(sWD) then Error "Cannot locate folder """ & sWD
& """"
07. If Not oFSO.FolderExists(sArchive) then Error "Cannot locate folder """
& sArchive & """"
08.
09. dYesterday = DateAdd("d", -1, Now())
10. sYesterday = 10000 * Year(dYesterday) + 100 * Month(dYesterday) +
Day(dYesterday)
11.
12. if not oFSO.FileExists(sFName) then Error "Cannot locate file """ &
sFName & """"
13. if oFSO.FileExists (sArchive & sYesterday & ".zip") then Error "Archive
file """ & sArchive & sYesterday & ".zip"" exists already!"
14. oFSO.MoveFile sFName, sArchive & sYesterday & ".zip"
15.
16. Sub Error(sMsg)
17. MsgBox sMsg
18. WScript.Quit
19. End Sub