![]() |
Rename multiple csv files eliminating (-) hyphens from the label.
How do I rename multiple csv files eliminating (-) hyphens from the label.
example of a file name 07-24-07-075339-2308-0-sales.CSV to 07240707533923080sales.CSV Thanks in advance, SimplyM |
Rename multiple csv files eliminating (-) hyphens from the label.
This code will do it: copy it, and paste it as a macro into a
spreadsheet. Before you run it you'll need to change the line that currently says FilePath = "c:\CSV Files\" to FilePath = "c:\Your Exact Directory Tree Here\" The code finds all the files in that directory with a CSV extension and renames them without hyphens to an XYZ extension. Then it changes the XYZ extensions to CSV. If the code changed the non-hyphenated form to CSV right away the program would loop endlessly. Sub CSV_No_Hyphen() Dim OrigName As String Dim FilePath As String Dim NewName As String Dim SheetName Dim K As Byte FilePath = "c:\CSV Files\" OrigName = Dir(FilePath & "*.csv") Do While OrigName < "" For K = 1 To Len(OrigName) - 4 If Mid(OrigName, K, 1) < "-" Then NewName = NewName & Mid(OrigName, K, 1) End If Next K FileCopy FilePath & OrigName, FilePath & NewName & ".xyz" NewName = "" Kill FilePath & OrigName OrigName = Dir Loop OrigName = Dir(FilePath & "*.xyz") Do While OrigName < "" NewName = Mid(OrigName, 1, Len(OrigName) - 4) FileCopy FilePath & OrigName, FilePath & NewName & ".csv" NewName = "" Kill FilePath & OrigName OrigName = Dir Loop End Sub |
Rename multiple csv files eliminating (-) hyphens from the label.
Thanks Dave it worked like a charm!
"simplymidori" wrote: How do I rename multiple csv files eliminating (-) hyphens from the label. example of a file name 07-24-07-075339-2308-0-sales.CSV to 07240707533923080sales.CSV Thanks in advance, SimplyM |
All times are GMT +1. The time now is 04:29 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com