![]() |
Replace first 8 letters of filename with Macro
Hi-
I have a bunch of files that all begin with a date - 20051231. After the date is the rest of the filename and this part of the filename varies. What I want to do is REPLACE the 20051231 portion of every file in a specific folder with FINAL 2005. To be more specific....I have over 1,000 files that each start with the date and then go on with a different name for each file. Example: 20051231_FileA 20051231_FileB 20051231_FileC I would like to keep the "FileA" portion of every file....but replace the 20051231 with FINAL 2005. Any ideas? Any help is greatly appreciated!! TIA, Chris |
Replace first 8 letters of filename with Macro
|
Replace first 8 letters of filename with Macro
Sub RenameFiles()
Dim List() as String, cnt as Long Dim fname as String cnt = 0 fname = Dir("C:\MyFolder\20051231_*.xls") do cnt = cnt + 1 redim preserve list(1 to cnt) list(cnt) = "C:\Myfolder\" & fname fname = dir() Loop while fname < "" for i = 1 to cnt Name list(i) as Replace(list(i),"20051231","FINAL 2005") Next End Sub -- Regards, Tom Ogilvy wrote in message oups.com... Hi- I have a bunch of files that all begin with a date - 20051231. After the date is the rest of the filename and this part of the filename varies. What I want to do is REPLACE the 20051231 portion of every file in a specific folder with FINAL 2005. To be more specific....I have over 1,000 files that each start with the date and then go on with a different name for each file. Example: 20051231_FileA 20051231_FileB 20051231_FileC I would like to keep the "FileA" portion of every file....but replace the 20051231 with FINAL 2005. Any ideas? Any help is greatly appreciated!! TIA, Chris |
Replace first 8 letters of filename with Macro
*** CAUTION: PERFORM TEST RUNS FIRST! ***
Working from the DOS Command Prompt (Start|Programs|Accessories|Command Prompt) navigate to the target directory. Enter "RENAME ????????*.* FINAL2005*.*" at the prompt, then hit Enter. Notice that there are 8 question marks, but FINAL2005 (without the space) is 9 characters. With your example filenames, the underscore will be replaced. ALSO, any files that have the same names following the underscore will NOT be renamed because there cannot be duplicate filenames. Create a mock directory, add dummy text files with the old filenames, then try this on them so as to get an understanding of how the DOS RENAME function works *** BEFORE *** the actual execution. -- Trent Argante [DC.J(n/a)] " wrote: Hi- I have a bunch of files that all begin with a date - 20051231. After the date is the rest of the filename and this part of the filename varies. What I want to do is REPLACE the 20051231 portion of every file in a specific folder with FINAL 2005. To be more specific....I have over 1,000 files that each start with the date and then go on with a different name for each file. Example: 20051231_FileA 20051231_FileB 20051231_FileC I would like to keep the "FileA" portion of every file....but replace the 20051231 with FINAL 2005. Any ideas? Any help is greatly appreciated!! TIA, Chris |
Replace first 8 letters of filename with Macro
Thanks Tom.
Don - Make sure there is a fileeditreplace option available before replying to any posts... Chris |
Replace first 8 letters of filename with Macro
Dim Filename As String
Dim Path As String Path = "c:\MyFolder\" Filename = Dir(Path & "2005*.txt") Do While Filename < "" Name Path & Filename As Path & Replace(Filename, Left(Filename, 8), "FINAL 2005") Filename = Dir Loop " wrote: Hi- I have a bunch of files that all begin with a date - 20051231. After the date is the rest of the filename and this part of the filename varies. What I want to do is REPLACE the 20051231 portion of every file in a specific folder with FINAL 2005. To be more specific....I have over 1,000 files that each start with the date and then go on with a different name for each file. Example: 20051231_FileA 20051231_FileB 20051231_FileC I would like to keep the "FileA" portion of every file....but replace the 20051231 with FINAL 2005. Any ideas? Any help is greatly appreciated!! TIA, Chris |
All times are GMT +1. The time now is 03:02 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com