Results 1 to 6 of 6

Thread: [RESOLVED] Rename file using label caption?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    8

    Resolved [RESOLVED] Rename file using label caption?

    I need some help with this one, so I hope someone could help me out

    I'll try and keep this simple:

    I'm reading from a file and extracting 3 strings from the file (abc.txt) and placing them into 3 seperate label captions.

    Example:

    Label1.Caption = "the cat" (strLine1)
    Label2.Caption = "sat on" (strLine2)
    Label3.Caption = "the mat" (strLine3)

    I then want to rename the same file (abc.txt) that was opened using common dialog to (the cat_sat on_the mat.txt)

    Hope someone wiil help this poor newb
    Last edited by Jon101; May 14th, 2006 at 04:00 PM.

  2. #2
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Rename file using label caption?

    To rename a file you can use 'Name filename As new filename'
    VB Code:
    1. Name "C:\abc.txt" As "C:\" & Label1.Caption & "_" & Label2.Caption & "_" & Label3.Caption & ".txt"

    casey.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    8

    Re: Rename file using label caption?

    Thanks for your help casey,
    Can I apply your suggestion if I am intending to use a common dialog to open the file (therefore file can be situated anywhere) and then allow the user to click a simple command button to rename the file?

    Also, Am I correct in my thinking that renaming a file is also overwriting the existing file?

    Thanks,

    Jon.

  4. #4
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Rename file using label caption?

    Yes. you can use that.

    And also,

    If you get an answer, please resolve the thread using Thread tools mark thread resolved.
    CS

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    8

    Re: Rename file using label caption?

    Thanks, I'll try it again then. I would've resolved earlier if I knew it was resolved.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Rename file using label caption?

    Quote Originally Posted by Jon101
    Also, Am I correct in my thinking that renaming a file is also overwriting the existing file?
    No, you're not. Overwriting the file destroys all the data in the file at the time it's overwritten. Renaming it merely changes the name, but leaves the contents intact.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

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