rename the filename thru vb

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vivekgrs
    New Member
    • Mar 2006
    • 11

    rename the filename thru vb

    hi everybody,

    iam using the following code for open the file.

    sfil = d:\abc.txt

    nSourceFile = FreeFile
    Open sfil For Input As #nSourceFile

    now i want 2 change the extension of the opened file to .bak. ie the original file wants 2 rename.



    can any one help me regarding this isssue

    regards

    vivek
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by vivekgrs
    hi everybody,

    iam using the following code for open the file.

    sfil = d:\abc.txt

    nSourceFile = FreeFile
    Open sfil For Input As #nSourceFile

    now i want 2 change the extension of the opened file to .bak. ie the original file wants 2 rename.



    can any one help me regarding this isssue

    regards

    vivek
    If you take a look at the file object which is part of the filesystemobjec t collection you will see that you can change the filename

    Comment

    • bobthenob
      New Member
      • Nov 2006
      • 4

      #3
      Name old name and path As new name and path
      hope this helps

      Comment

      • Chish
        New Member
        • Feb 2007
        • 1

        #4
        That doesn't work with files that need to be overwritten.
        An error saying that the file already exists pops up.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by Chish
          That doesn't work with files that need to be overwritten.
          An error saying that the file already exists pops up.
          Perhaps so, but that wasn't part of the original question.

          Also, it's worth noting that while statements such as Name As are quick and simple to code, the FileSystem Object gives you much more power and control over the file system.

          Comment

          • balid
            New Member
            • Feb 2007
            • 18

            #6
            Originally posted by Killer42
            Perhaps so, but that wasn't part of the original question.

            Also, it's worth noting that while statements such as Name As are quick and simple to code, the FileSystem Object gives you much more power and control over the file system.

            Plus you can override the warning message this way as well.

            Comment

            Working...