PDA

Click to See Complete Forum and Search --> : Renaming Files


madddog
Jan 27th, 2000, 08:28 AM
I have a whole directory of that my program needs to rename.

This is a sample of what the files look like, they all have different names, but I need to retain the first 8 characters an the last 3 (extension).

1573-001111.doc
1822-309369.doc
etc...

I have seen somewhere on how to rename files by stripping out unnessary text, I don't remember where or what to do.

Thanks,
Mike

Aaron Young
Jan 27th, 2000, 09:58 AM
Use the Name.. As.. Statement, ie.
Dim sDir As String
sDir = Dir("C:\Files\*.doc")
While Len(sDir)
If (GetAttr("C:\Files\" & sDir) And vbDirectory) <> vbDirectory Then
Name "C:\Files\" & sDir As "C:\Files\" & Left$(sDir, 8) & Right$(sDir, 4)
End If
sDir = Dir
Wend

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com

madddog
Jan 27th, 2000, 10:18 AM
Thanks,


It worked perfectly

Mike

madddog
Jan 27th, 2000, 01:11 PM
Ok, I ran into a snag, not all the files follow the same form as what I thought.

How do I use the middle command to strip out 7 characters in the middle of the file names. The only thing consistant is that the beginning of the characters to remove are counted from the right.

ex: 1573-0011*******.doc

what I ran into is that all the files were not named correctly.

Any help would be greatly appreciated,

Mike