+ Reply to Thread
Results 1 to 6 of 6

Thread: Prefix all file names within a folder

  1. #1
    Registered User
    Join Date
    04-15-2011
    Location
    Fordoun, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    11

    Smile Prefix all file names within a folder

    Hi All

    I am new to Excel VBA and would appreciate any help I can get!

    I am trying to prefix all the files in a folder ready for archiving. I want if possible to input the folder the files are located in and also the prefix that should be added by inputboxes.

    Is this possible and if so can anyone show me how this is done?
    Last edited by stawil; 06-10-2011 at 09:00 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Prefix all file names within a folder

    Hi,

    Please give us more information
    let your folder will be at path c:\files
    - would you like to list all files from that directory ?
    - would you like to change names of those files / move to other place /delete them
    - what kind of files *.xls ? *.txt ? *.* you have

    Give more info and I think someone will be able to do everthing You will need.

    Best Regards

  3. #3
    Registered User
    Join Date
    04-15-2011
    Location
    Fordoun, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Prefix all file names within a folder

    Sorry about the lack of detail but the following are the files etc I would wish to change.

    Path: F:\General\Quarterly Absence Report\"Folder Name"\*.*files

    I would wish to use the exsisting file name then prefix all the files within the "Folder Name" with prefix entered e.g.

    F:\General\Quarterly Absence Report\Fin Year 200708\April.xls
    F:\General\Quarterly Absence Report\Fin Year 200708\Absence Stats.xls

    would be renamed as

    F:\General\Quarterly Absence Report\Fin Year 200708\200708 April.xls
    F:\General\Quarterly Absence Report\Fin Year 200708\200708 Absence Stats.xls

    I would like to be able to have an input box for the folder and prefix if possible and all the files are either .xls or .doc.

    Hope this helps, not too good and explaining things, but appreciate your help.

  4. #4
    Registered User
    Join Date
    04-15-2011
    Location
    Fordoun, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Prefix all file names within a folder

    I have been trying to alter a solution given for renaming a file with a suffix and was wondering if this code could be altered to rename existing files by prefixing the file name with a variable input whilst leaving them in exactly the same location. I am looking to rename only.

    I do not follow or understand the below code enough to alter to my requirements, but hope that someone out there (hopeful the person who wrote the original code) can help me........please!!!

    Code:

    Sub RenameFiles()

    Dim FileName As String
    Dim FilePath As String
    Dim NewFileName As String
    Dim RegExp As String
    Dim vFolder As Variant

    FilePath = "C:\Fin Year 200809\"

    ' Set RegExp = CreateObject("VBScript.RegExp")
    ' RegExp.IgnoreCase = True
    ' RegExp.Pattern = "(.+)(O\-.+)(\..*)"
    RegExp = InputBox("Please enter your required prefix: e.g. 200708")



    For Each vFolder In Array("Craig Clement", "Support Staff")
    FileName = Dir(FilePath & vFolder & "*.*")
    While FileName <> ""
    If RegExp.Test(FileName) Then
    NewFileName = RegExp.Replace(FileName, "$1$3")
    Name FilePath & vFolder & FileName As FilePath & vFolder & NewFileName
    End If
    FileName = Dir()
    Wend
    Next vFolder

    End Sub

    Code/

    Code:

  5. #5
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Prefix all file names within a folder

    I'm sorry that I'm not explained provoded script, but I hope that presented solution will cover your need.

    Please check examples in attached zip file.

    p.s. there no prefix validation for now, so you should tape only alfanumerical symbols correct for windows path

    Best Regards
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    04-15-2011
    Location
    Fordoun, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Prefix all file names within a folder

    maczaq.....thank you so much........works a treat and also response was so quick..again thank you.......Best Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0