Computing.Net > Forums > Windows 2000 > Renaming files with VB Script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Renaming files with VB Script

Reply to Message Icon

Name: Kiwitrouble
Date: April 8, 2003 at 07:49:40 Pacific
OS: Win 2000
CPU/Ram: p4800/256
Comment:

Can anyone help me develop a script to rename files in the current directory in the following format based on when the original files were saved i.e.

Original file names

111-1175_IMG.JPG
111-1176_IMG.JPG
111-1177_IMG.JPG
...

Too

04042003-01.JPG
04042003-02.JPG
04042003-03.JPG
...

Thx

J




Sponsored Link
Ads by Google

Response Number 1
Name: PeteN
Date: April 8, 2003 at 14:54:17 Pacific
Reply:

This should be posted over in the programming forum but I think that this should do the trick.

Dim strY, strM, strD, strDate, strFile, strOrig, strNew
Dim fs, f, f1, fc, s, strFolder, WshShell, fname, intCount

on error resume next


' USER CONFIG AREA
dteData = now() 'Current Date
strfolder = "c:\test\" 'Folder


intCount = 0
strY = ltzero(Year(dteData)) 'Year
strM = ltzero(Month(dteData)) 'Month
strD = ltzero(Day(dteData)) 'Day

strFile = stry & strM & strD 'Filename

set fs = CreateObject("Scripting.FileSystemObject")
set f = fs.GetFolder(strfolder)
Set fc = f.files

For Each f1 in fc
strOrig = strfolder & f1.name
intCount = intCount + 1
aryFile = Split(f1.name, ".", -1, 1)
strNew = strfolder & strFile & "-" & ltzero(intCount) & "." & aryFile(ubound(aryFile))
fs.movefile strOrig, strNew
Next


function ltzero(intVar)
if intVar 10 then
ltzero = "0" & intVar
else
ltzero = intvar
end if
end function


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows 2000 Forum Home


Sponsored links

Ads by Google


Results for: Renaming files with VB Script

rename files www.computing.net/answers/windows-2000/rename-files/45953.html

copying files with Task Scheduler www.computing.net/answers/windows-2000/copying-files-with-task-scheduler-/63510.html

Batch File to Copy file with greate www.computing.net/answers/windows-2000/batch-file-to-copy-file-with-greate/61475.html