#1
|
|||
|
|||
Add text to all file names in folder
I have 3 folders (vol 1,2 and 3). some of the folders have the same file name("contents" for example). I need to copy all of these files into one folder but with some having identical file names that creates a problem.I'm hoping someone can help me out.I'd like to be able to drill down to a folder,select it and then simply add text ahead of the file name.example, I could select Vol 1 folder and insert the text "Vol1" into each file name ,then the file "contents" in the vol 1 folder would become "vol1contents",etc. Does this make sense? Thanks in advance!! Greg |
#2
|
||||
|
||||
Hi Greg,
Try something like: Code:
Option Explicit Dim StrIO As String Sub BulkCopier() Application.ScreenUpdating = False Dim strInFolder As String, strOutFolder As String Dim strInFile As String, strOutFile As String Dim StrPrefix As String StrIO = "Choose an INPUT folder" strInFolder = GetFolder If strInFolder = "" Then Exit Sub StrIO = "Choose an OUTPUT folder" strOutFolder = GetFolder If strOutFolder = "" Then Exit Sub StrPrefix = "\" & Split(strInFolder, "\")(UBound(Split(strInFolder, "\"))) & "_" strInFile = Dir(strInFolder & "\*.doc", vbNormal) While strInFile <> "" On Error Resume Next FileCopy strInFolder & "\" & strInFile, strOutFolder & StrPrefix & strInFile strInFile = Dir() Wend Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, StrIO, 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Add text to all file names in folder
Macropod,
That worked great! I would like to modify a little though. The folder I selected is:2012 Operating Procedures - Vol I,and one of the many files in that folder is called "Contents" The code resulted in : 2012 Operating Procedures - Vol I_Contents,etc... Which worked very smooth and is probably the way I portrayed what I needed. Would it be difficult to edit the code so that it asks for a prefix to add, for exampl I would input "Vol 1", and the result would be "Vol I_Contents",or "Greg" and get "Greg_Contents", as an example? I can live with the code you provided ,it works very smooth,I'd just like to have a little more flexibility in the prefix that s added. Thanks so much! Greg |
#4
|
||||
|
||||
Hi Greg,
That's easy. Simply change: StrPrefix = "\" & Split(strInFolder, "\")(UBound(Split(strInFolder, "\"))) & "_" to: StrPrefix = "\" & InputBox("What label do you want to prefix the files with?", "File Prefixer") & "_"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to enter names in Resource Pool/names | pstein | Project | 1 | 03-26-2012 07:37 AM |
Setting file open folder options | KevinJ | Word | 1 | 10-15-2011 05:51 AM |
Outlook2003 - how to write attached file to folder | nodari | Outlook | 1 | 05-26-2011 08:51 AM |
find author names in text | anil3b2 | Word | 0 | 08-02-2010 04:12 AM |
Two Different Names in the Same File | kathy carson | Outlook | 0 | 02-14-2006 01:02 PM |