Jump to content

Having full path from file name...


Recommended Posts

I am making a func that uses FileFindNextFile() for rolling files in a folder, so far so good. The parameter of this search is a full path with wildcards.

E.g. c:\hello\*.*

The result of the next FindNextFile() are without the path!

How can I have it back? I thought FileGetShortName or LongName had this function but I was wrong. I checked in the help file but I am still solution-less.

:ph34r:

Link to comment
Share on other sites

Hmmm....in my 'search'-functions I always put the path and filename independent to the FileFind....

Like:

$path = "C:\Test\"

$file = "*.*"

$search = FileFindFirstFile($path & $file)

...

Do you understand what I mean?

You can now later use the 'saved' path...

Link to comment
Share on other sites

If anyone can have my same problem...

($a is just an example)

Dim $a, $path, $file, $c
; $a is the starting point. It may be a full path or just a filename.

$a = c:\temp\name.txt

   If Not StringInStr($a, "\") Then
      $path = @WorkingDir & "\"
    ;and $file = $file;-D
   Else
      For $C = StringLen($a) To 1 Step - 1
         If StringMid($a, $C, 1) = "\" Then
            $PATH = StringLeft($a, $C)
            $FILE = StringTrimLeft($a, $C)
            ExitLoop
         EndIf
      Next
   EndIf

MsgBox(0,"",$path & "       " & $file)

Edit: Improved code.

Edited by ezzetabi
Link to comment
Share on other sites

I agree with the others, it's typically easier to save the path in a separate array for later use. However you can also use the @WorkingDir macro to obtain the name of the current working directory.

If you only have access to the full filename, along with path (ie: [full path]\[filename].[ext]) then you can use the StringSplit function to make it easy to separate the file name and path.

Several months ago, I posted an example of how to search the entire computer for a specified file. The code is very slow but it could be optimized for your needs. Feel free to check out this post, if you're curious.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...