Results 1 to 4 of 4

Thread: Renaming Files

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    Nashville, TN
    Posts
    114

    Post

    I have a whole directory of that my program needs to rename.

    This is a sample of what the files look like, they all have different names, but I need to retain the first 8 characters an the last 3 (extension).

    1573-001111.doc
    1822-309369.doc
    etc...

    I have seen somewhere on how to rename files by stripping out unnessary text, I don't remember where or what to do.

    Thanks,
    Mike

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Use the Name.. As.. Statement, ie.
    Code:
    Dim sDir As String
    sDir = Dir("C:\Files\*.doc")
    While Len(sDir)
        If (GetAttr("C:\Files\" & sDir) And vbDirectory) <> vbDirectory Then
            Name "C:\Files\" & sDir As "C:\Files\" & Left$(sDir, 8) & Right$(sDir, 4)
        End If
        sDir = Dir
    Wend
    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    ajyoung@pressenter.com


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    Nashville, TN
    Posts
    114

    Post

    Thanks,


    It worked perfectly

    Mike

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    Nashville, TN
    Posts
    114

    Post

    Ok, I ran into a snag, not all the files follow the same form as what I thought.

    How do I use the middle command to strip out 7 characters in the middle of the file names. The only thing consistant is that the beginning of the characters to remove are counted from the right.

    ex: 1573-0011*******.doc

    what I ran into is that all the files were not named correctly.

    Any help would be greatly appreciated,

    Mike

Posting Permissions

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



Click Here to Expand Forum to Full Width