Re: Renaming files in a folder by \
\
Mon May 08 19:46:50 CDT 2006
> I have a folder with files named 20060408AL.txt, 20060409AL.txt,
> 20060410AL.txt, etc. The files use the date and add an "AL" to the end. Can
> someone help me with a script that renames each file within a folder and
> "strips" the "AL" part at the end?
> The end result would convert 20060417AL.txt to 20060417.txt.
There is no "rename" method, but "move" has the same effect if the file is moved
to the same directory with a new name. The script below will remove the "AL"
from the end of all filenames in a specified root folder and its subfolders.
'-----------Rename.vbs---------------
Set fso = CreateObject("Scripting.FileSystemObject")
set root=fso.getFolder("d:\path")
call folderlist(root)
sub folderlist(grp)
call filelist(grp)
for each fldr in grp.subFolders
set nf=fso.GetFolder(fldr.path)
call folderlist(nf)
set nf=nothing
next
end sub
sub filelist(grp)
for each file in grp.files
name=file.name
path=file.path
path=mid(path,1,len(path)-len(name))
name=replace(ucase(name),"AL.TXT",".txt")
file.move path & name
next
end sub
'------------------------------------------
It can be simplified if you are not concerned with subdirectories.
--
Crash
"In war there is no substitute for victory."
~ General Douglas MacArthur ~