Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming Files in a Directory 2

Status
Not open for further replies.

PaullyB

Programmer
Feb 1, 2001
5
0
0
US
I need to rename all files in a directory on an NT Server. The current filenames are *_*.wmf

I need to strip out the _* from the name.

For example, a file named AOL_1.wmf should be renamed to AOL.wmf

Does anybody know an easy way to do this for all files in a directory via a VB executable or .bat file?
 
I don't know if this will help you but you might do the following:

Dim FSO
Dim mFile
Dim strWork

Set FSO = CreateObject("Scripting.FileSystemObject")

For Each mFile In FSO.GetFolders("C:\Temp").Files
strWork = Left(mFile.Path,Instr(1,mFile.Path,"_")-1)
strWork = strWork & FSO.GetExtensionName(mFile.Path)
FSO.CopyFile mFile.Path,strWork
mFile.Delete
Next

Try this out and see if it works. It should copy the file as the new file name then delete it afterwards

John Whyte
jwhyte@skipton.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top