Results 1 to 7 of 7

Thread: Rename a file ?

  1. #1

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Question

    I have not used VB for this before. I guess it's possible, but is there a property / method for renaming a file (I need it for the extension part really) - ie; rename file.doc to file.xls.

    Thank you

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  2. #2
    Addicted Member Michael Woolsey's Avatar
    Join Date
    Nov 2000
    Location
    Calgary, Alberta, Canada.
    Posts
    243
    Try the Name command.

    Code:
    Name oldpathname As newpathname
    Hope this helps.
    Michael
    Application/Web Developer

    Visual Basic 6.0 SP5
    Active Server Pages
    Oracle 9i
    - I'm going to live forever, or die trying!

  3. #3
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    Try

    Code:
    shell "Rename " & yourOldFile & " " & Left(yourOldFile,len(youOldFile)-4) & ".xls"
    you can change Left(yourOldFile,len(youOldFile)-4) by
    your function if you want,it's just to put your file
    without the extention.

    Or you just can use
    FileCopy yourOldFile,yourNewFile
    Kill yourOldFile

  4. #4

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    ahhhhhh, thank you for that one, I was looking at change name, alter, ren, rename, everything but

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Yeah I agree with Michael, use NAME, but be sure to include the whole directory with it:

    Code:
    Name "c:\mypath\myfile.ext" As "c:\mypath\myfile\mynewfile.ext"
    
    
    so you can also use it to Move files.
    
    Name "c:\file" As "c:\jop\file"
    Have fun!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Remeber, by changing the extension of a file you are not changing the type of the file and if you do something like this.
    Code:
    Private Sub Command1_Click()
    
        Dim sold As String, snew As String
        sold = "C:\my documents\MyWord.doc"
        snew = "C:\my documents\myword.xls"
        
        Name sold As snew
    
    End Sub
    ..the result will be an unstable file
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    awkward one

    Thank you HeSaidJoe. For this one, I realise this well raised point, but this program is for being devious.

    I (like 99% of people methinks) get lots of jokes & pics in their e-mails which I forward. One of my mates companies have upgraded their firewalls though & this won't allow any files other than with MSOffice extensions through.

    Solution - a great little program by Alex. I rename the file to .doc my end, send it through with note of what the extension should be.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

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