• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

change extension of multiple csv files

goodfriend40

New Member
Hello,

i have to work with say 50 csv files. file name contain a name and date. i want to keep only name of csv file instead of name + date. is there a shortcut , where i can make batch file so my all csv file name changes at a stroke of key. ie macro or batchfile. as it is daily job
 
Can you be more specific in the naming structure? (examples?)

Each of these has a different solution:

Chandoo_3_21_2011.csv

Chandoo 3_21_2011.csv

ChandooMarch212011.csv
 
NAMES ARE SAY JAM 31-MAR-2011.CSV, BREAD 31-MAR-2011.CSV, BUTTER 31-MAR-2011.CSV, BISCUIT 31-MAR-2011,CHEESE 31-MAR-2011.CSV AND SO ON
 
Run this from a module in XL. Note that you need to change the folder name as appropriate.

[pre]
Code:
Sub ReNameFiles()
Dim MyPath As String, FilesInPath As String
Dim MyFiles() As String
Dim SourceRcount As Long, FNum As Long, x As Long
Dim NewName As String

' Change this to the pathfolder location of your files.
MyPath = "C:My Documents"

' Add a slash at the end of the path if needed.
If Right(MyPath, 1) <> "" Then
MyPath = MyPath & ""
End If

' If there are no desired file type in the folder, exit.
FilesInPath = Dir(MyPath & "*.csv")
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If

' Fill the myFiles array with the list of files
' in the search folder.
FNum = 0
Do While FilesInPath <> ""
FNum = FNum + 1
ReDim Preserve MyFiles(1 To FNum)
MyFiles(FNum) = FilesInPath
FilesInPath = Dir()
Loop

'Loops through files and renames
If FNum > 0 Then
For FNum = LBound(MyFiles) To UBound(MyFiles)
x = InStr(1, MyFiles(FNum), " ")
If x <> 0 Then 'File name does not have a space
NewName = Left(MyFiles(FNum), x - 1) & ".csv"
Name MyPath & MyFiles(FNum) As MyPath & NewName
End If
Next
End If
End Sub
[/pre]
 
Back
Top