Results 1 to 10 of 10

Thread: rename files

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    302

    rename files

    Is it possible to rename all the .jpg files in a folder... The new name should be continues, 1, 2, 3, 4...

    ex: (how do I get the new name?)
    old name new name
    text001.jpg 1.jpg
    text003.jpg 2.jpg
    text007.jpg 3.jpg
    text009.jpg 4.jpg
    text015.jpg 5.jpg
    text016.jpg 6.jpg

    any ideas?


    thanks

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Use Name
    VB Code:
    1. Name oldName As NewName

    What are all ur .jpg currently loaded in? An Array?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    302
    Bruce Fox: I don't know how to load the current file names in order...

    Can you help?


    thanks

  4. #4
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    this is an exectuable that I made recently. It does just what you're asking. I don't remember what controls I used, but it should work if you have vb6.

    No viruses.
    Attached Files Attached Files

  5. #5
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    Here's the source code. It doesn't have a lot of error handling since I only made it for me, but I haven't had it crash on me either.
    Attached Files Attached Files

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Something like:
    VB Code:
    1. Private Sub Form_Load()
    2. Dim arr() As String
    3. Dim sBuff As String
    4. Dim i As Long
    5.  
    6.     sBuff = Dir("C:\New\*.jpg")
    7.    
    8.     Do
    9.         ReDim Preserve arr(i)
    10.         arr(i) = "C:\New\" & sBuff
    11.         sBuff = Dir
    12.         If sBuff = "" Then Exit Do
    13.         i = i + 1
    14.    Loop
    15.     For i = 0 To UBound(arr) 'Rename each file starting with 1
    16.         Name arr(i) As ("C:\New\" & i + 1 & ".jpg") 'Both paths MUST be the same
    17.     Next
    18. End Sub

    NB:Practive on backup file first.
    Last edited by Bruce Fox; Apr 8th, 2002 at 08:19 PM.

  7. #7
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    hi,

    i have one text file i need renaming. Can i simply do this using 1 line of code?

    Thanks
    Nick

  8. #8
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    name oldfilename as newfilename

  9. #9
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    ****....

    it says that in the first reply!

    sorry!

  10. #10
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Opps,

    Should be:
    VB Code:
    1. For i = 0 To UBound(arr) 'Rename each file starting with 1
    2.         Name arr(i) As ("C:\New\" & i + 1 & ".jpg") 'Both paths MUST be the same
    3. Next

    U can also get rid of that ReDim statement (I have already edited ubove)
    Last edited by Bruce Fox; Apr 8th, 2002 at 08:22 PM.

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