On Oct 28, 3:58 pm, Jake <jak
...@gmail.com> wrote:
> Hi,
> I have a file called C:\MyDir\MyFile.dat which is copied to this folder
> automatically each night.
> I need to keep a copy of this file for the seven last days. Hence I
> need to have the file renamed to the day of week, overwriting the old
> filenames. The result should be a set of files Thursday.dat,
> Friday.dat, Saturday.dat... etc in C:\MyDir.
> How would I do this in vbscript? I'm realtively new to this, but I want
> to learn :-)
> thanks anyone
> jake
you can using weekday(),retrun 1,2,3,.. then rename to Weekday.
Option Explicit
'~~ 2009/09/27 renname to yyymmdd*.jpg
'~~ 2007/08/28
'~~ Backup file *.nsf file to *_yyyymmdd.nsf
'~~ whs %shell%\rename_scanimage.vbs
Dim wdate
Dim oShell
Dim source , target, tmpfile,tmpfile1
Dim fso
dim WshShell, intButton,ObjExec,folder,file
dim cnt
Set fso = CreateObject("Scripting.FileSystemObject")
'~~ wDate = Year(Now) & Right("00" & Month(Now), 2) & Right("00" & Day
(Now), 2)
cnt = 0
Set WshShell = Wscript.CreateObject("Wscript.Shell")
set folder = fso.GetFolder (".") '~~ Currenty Directory
for each file in folder.Files
if fso.GetExtensionName (file.Path) = "jpg" then
if left(file.name,7) = "Picture" then
cnt = cnt + 1
'~~~tmpfile = wDate & "_" & cnt & ".jpg"
WScript.Echo file.name & " " & tmpfile
tmpfile1 = year(file.DateLastModified) & _
right("00" & Month(file.DateLastModified),2) & _
right("00" & day(file.DateLastModified),2) & "_" & _
right("000" & cnt,3) & ".jpg"
WSCript.echo tmpfile1
'~~ if file name existing
'~~ Start rename
fso.movefile file.name , tmpfile1
end if
end if
next
Set oShell = Nothing
Set folder = Nothing
Set fso = nothing
set WshShell = nothing