Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-03-2012, 09:26 AM
cure4glass cure4glass is offline Add text to all file names in folder Windows Vista Add text to all file names in folder Office 2007
Novice
Add text to all file names in folder
 
Join Date: Feb 2012
Posts: 7
cure4glass is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 04-06-2012, 03:46 AM
macropod's Avatar
macropod macropod is offline Add text to all file names in folder Windows 7 64bit Add text to all file names in folder Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
You'll get prompted to select the input and output folders. The macro will copy all files from the input folder to the output folder, prefixing them with the input folder's name.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-06-2012, 03:55 PM
cure4glass cure4glass is offline Add text to all file names in folder Windows Vista Add text to all file names in folder Office 2007
Novice
Add text to all file names in folder
 
Join Date: Feb 2012
Posts: 7
cure4glass is on a distinguished road
Default 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
Reply With Quote
  #4  
Old 04-06-2012, 04:23 PM
macropod's Avatar
macropod macropod is offline Add text to all file names in folder Windows 7 64bit Add text to all file names in folder Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply



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
Add text to all file names in folder Setting file open folder options KevinJ Word 1 10-15-2011 05:51 AM
Add text to all file names in folder 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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:14 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft