Renaming a file

How can I rename a file in a known directory (there is only going to be one file in the directory) when I will not always know the exact name of the file. Apparently the NAME statement cannot use wildcards.

Comments

  • : How can I rename a file in a known directory (there is only going to be one file in the directory) when I will not always know the exact name of the file. Apparently the NAME statement cannot use wildcards.
    :

    Use the Dir function to search for the file in the directory.

    Greets...
    Richard

  • : : How can I rename a file in a known directory (there is only going to be one file in the directory) when I will not always know the exact name of the file. Apparently the NAME statement cannot use wildcards.
    : :
    :
    : Use the Dir function to search for the file in the directory.
    :
    : Greets...
    : Richard
    :
    :
    He said: "I will not always know the exact name of the file". How he is going to search Directory using Dir(), if doesn't know file name?
    There must be some API function that retrieves file name but I forgot which one :-(
  • : : : How can I rename a file in a known directory (there is only going to be one file in the directory) when I will not always know the exact name of the file. Apparently the NAME statement cannot use wildcards.
    : : :
    : :
    : : Use the Dir function to search for the file in the directory.
    : :
    : : Greets...
    : : Richard
    : :
    : :
    : He said: "I will not always know the exact name of the file". How he is going to search Directory using Dir(), if doesn't know file name?
    : There must be some API function that retrieves file name but I forgot which one :-(
    :
    I thing API tht maigt be used is BrowseForDirectory
  • : : : : How can I rename a file in a known directory (there is only going to be one file in the directory) when I will not always know the exact name of the file. Apparently the NAME statement cannot use wildcards.
    : : : :
    : : :
    : : : Use the Dir function to search for the file in the directory.
    : : :
    : : : Greets...
    : : : Richard
    : : :
    : : :
    : : He said: "I will not always know the exact name of the file". How he is going to search Directory using Dir(), if doesn't know file name?
    : : There must be some API function that retrieves file name but I forgot which one :-(
    : :
    : I thing API tht maigt be used is BrowseForDirectory
    :
    U said that the path is known to U, and U know that there will be only one file in the directory but U don't know the exact name of the only file existing in that directory.

    In this case to rename the file yasily U don't need to call any API. U can put a filelist contorl in the form and set its path to the path of UR directory. Then U can get the name of the file from the filelist cotrol (as far as I can remember U can get the file name by using the index property). Thats all, once u got the old file name U cna do the rest.
    GoodLuck.
    _____________________________________________________________________________
    Knowledge Is Power. Be Sure To Use This Power For Others WelFare. (;->

  • If you'd familiarize yourself with the Dir function somewhat, you should know that it supports the use of wildcard parameters.
    If he knows the directory, then using Dir IS the way to go...
    No need to tend to API's when VB supplies you with perfectly good functions to do the job.

    Here's an example:
    [code]
    Directory:
    C:My Files
    Contains:
    My files.txt

    Code:

    Dim sFile As String

    sFile = Dir$("c:my files*")
    'Do anything you like with the file here
    [/code]

    In any case, you'll need to know the directory.

    Greets...
    Richard

  • :
    You are right about Dir(). Don't use VB 6 for a long time ... :-o
  • [b][red]This message was edited by Shoaib Nawaz at 2005-9-24 15:3:39[/red][/b][hr]
    'A Folder is located at App.path having name MyFolder
    'It contains a file (Name Unknown)

    Path = App.Path & "MyFolder"
    'If the extension is also unknow use "*.*" instead "*.txt"
    FileToChange = Dir(Path & "*.txt")
    Name Path & FileToChange As Path & "Newname.txt"

    Reply Me If your problem is solved.





Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories