renaming files using excel


Posted by Alex on March 13, 2001 3:35 AM

Does anybody know how to rename a list of files with data in columns from excel? Is there a renaming programme into which you can cut and paste the new filenames you want? Or maybe a macro within excel that can be used?
Is a difficult problem and cannot seem to find the answer - advice would be much appreciated.

Posted by ml on March 13, 2001 12:32 PM

Are you saying you have something like existing filenames in column A and
new filenames corresponding in column B and you want something to rename
each entry in A to the name in B?

Posted by Alex on March 14, 2001 1:13 AM

That is exactly what I mean - do you know how to do this?

Posted by Alex on March 14, 2001 1:16 AM

That is exactly what I mean - do you know how to do this?
Also it would be usefull to be able to read the original list of filenames into a column in Excel, but I don't know if this is possible either. Maybe they can be copied to the clipboard somehow and then pasted in?



Posted by ml on March 14, 2001 12:04 PM

To pull in a directory list:

#substitute the ListDir variable and *.xls as appropriate

Sub DirList()
Const ListDir = "C:\Data\"
If Not Dir(ListDir & "*.xls") = "" Then
FList = Dir(ListDir & "*.xls")
R=1
Do Until FList = ""
Cells(R,1).Value = ListDir & FList
R = R + 1
Flist = Dir
Loop
End If
End Sub


If you have filenames in Col A that need to be changed to Col B:

Sub RenameFiles()
For I = 1 to Range("A1").End(xlDown).Row
OldFileName = Cells(R,1).Value
NewFileName = Cells(R,2).Value
If Not Dir(OldFileName) = "" Then Name OldFileName as NewFileName
Next
End Sub