Sign in to follow this  
Followers 0
a6m1n0

How to find file and return it's path to string

13 posts in this topic

Hi. Was wondering how I can find file and return it's path to string to autoit. I can of course use dir c:\filename.ext /s /b to return something in the cmd window or redirect/pipe it somewhere, but two probelms: 1) How to get this data into autoit as string if I use DIR, and 2) is there a better way to do this just using autoit?

Some constants:

The drive searched will always be C:

The file searched for will always have the same name (8.3 format)

Thanks

Share this post


Link to post
Share on other sites



Thanks for the tips Larry...I'll do that.

Share this post


Link to post
Share on other sites

Ok, performed a search and found this script written by you Larry:

http://www.autoitscript.com/forum/index.ph...owtopic=571&hl=

The problem is when I attempt to Beta Run in SciTE with the example usage you provided (searching for *.au3 files) the following error is returned:

ERROR: FileFindNextFile() [built-in] called with wrong number of args.

$szBuffer = FileFindNextFile()

Actually it reports an error for each line that FileFindNextFile() is used. Am I just misusing your script? (Not unlikely :$ )

Share this post


Link to post
Share on other sites

Ok, performed a search and found this script written by you Larry:

http://www.autoitscript.com/forum/index.ph...owtopic=571&hl=

The problem is when I attempt to Beta Run in SciTE with the example usage you provided (searching for *.au3 files) the following error is returned:

ERROR: FileFindNextFile() [built-in] called with wrong number of args.

$szBuffer = FileFindNextFile()

Actually it reports an error for each line that FileFindNextFile() is used. Am I just misusing your script? (Not unlikely :$ )

<{POST_SNAPBACK}>

you have to assign a variable to your filefindfirstfile and pass it to FileFindNextFile()...example

; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile("*.*")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    
    MsgBox(4096, "File:", $file)
WEnd

; Close the search handle
FileClose($search)

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Ah ok. DOH! Thanks for the tip. (Man, you guys are fast!)

Modified like so: FileFindNextFile($szSearchString), where $szSearchString is the argument passed to the function that Larry wrote. Works perfectly.

Again, thanks for the help and the code. ;)

Share this post


Link to post
Share on other sites

Ah ok. DOH! Thanks for the tip. (Man, you guys are fast!)

Modified like so: FileFindNextFile($szSearchString), where $szSearchString is the argument passed to the function that Larry wrote. Works perfectly.

Again, thanks for the help and the code. ;)

<{POST_SNAPBACK}>

NP, glad i could help. as far as speed of answer... i'm at work... what else is there to do?

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Ok, I cannot seem to get Larry's function to return a path and I am sure it is because I am a newb and am still learning. Let me rephrase: it returns all paths relative to the root directory of the drive--and this I am sure is beacause I modified the code (just what I mentioned above only), but only b/c out of the box it didn't work at all, and again I am sure this also is attributed to my newbness. :">

Since I need sciprts that are more 'out-of-the-box' so to speak until I can get the hang of this, I searched again for 'findfile' and ran across this URL with findfiles.au3:

http://www.autoitscript.com/fileman/users/jdeb/jdeb_autoit_stuff.htm

This script works really well, but fails Beta Run with SciTe if $DIR is defined as 'c:\'. How do I use this script to start it's search from the root directory of c:\? I have tried escaping the backslah eg 'c:\\' to account for the trimming of that slash, also tried 'c:\.' and 'c:\..' just for the heck of it and received the expected error.

The error that is returned by SciTe is when $DIR = "c:\" or "c:" :

Line 42: Invalid file handle used

Line 42 is:

$N_FILE = FileFindNextFile($N_SEARCH)

I 'kind of' understand the error from reviewing the AutoIt help again, but for the life of me I could not articulate this, nor could I modify to suit my needs; me=newb, remember?

Any help appreciated. Thanks for tolerating me. ;)

Share this post


Link to post
Share on other sites

This is a easy way to search for something if using xp and it can be modified for win95-98

; Script start ---->

$file1 = "new.txt" ; you can change this to any file name you want

FileChangeDir("C:\") ; specified directory to search including sub directories 'this case entire C drive'

$d = "dir /b /s " & $file1 & " > C:\temp\file.txt" ; these two lines send the file name to the command prompt

RunWAIT(@ComSpec & " /C " & $d, "", @SW_HIDE);and put the output into a text document in temp folder

;<-------- End

then you could use the function (_FileCountLines) to get the number of files that search returned in file.txt

and you could also use the function (filereadline) in a loop to assign each full path its own variable

Share this post


Link to post
Share on other sites

Thanks for the help Digetal.

I am trying to keep from having to write a temp file somewhere since this can cause problems with what I am trying to do, and would take to long to explain here--nothing top secret or anything, just would take to long. There has to be way to do this without writing a tmp file though, isn't there?

I do appreciate the help and the swift reply, just need to know if this is possible or not with that script; well JdEb would know for certain I'm sure since it's his script.

Thanks

Share this post


Link to post
Share on other sites

I downloaded the script and tested it using winxp and autoit v3.1.1.75 (beta) and it works

change

Dim $DIR="c:\winutil\autoit3\programs\test" ; specify the directory to search

to

Dim $DIR="c:\" ; specify the directory to search

run in beta run mode from scite

it does reply alot of files in my case 1,432

and was giving the directories of each in a message box

ohh, and you have to open scite and goto tools beta run

can't just click and run script doesn't work

to complie use bet complie for scite

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Ok, I think I need to upgrade to the latest Beta version. Again Thanks for the help Digetal...I'll give it a go and reply back here. ;)

EDIT: And yeah, I only use SciTe for builds and runs. :P

Edited by a6m1n0

Share this post


Link to post
Share on other sites

Awesome tip Digetal--That was the problem on this end. I downloaded the v3.1.1.75 (beta) zip file, after backing up the autoit program directory I unzipped the files, ran SciTe and a Beta Run--did not return any errors.

Thanks for the help! Hope I can return the favor sometime. ;)

Share this post


Link to post
Share on other sites

Awesome tip Digetal--That was the problem on this end. I downloaded the v3.1.1.75 (beta) zip file, after backing up the autoit program directory I unzipped the files, ran SciTe and a Beta Run--did not return any errors.

Thanks for the help! Hope I can return the favor sometime. :P

Hello

I know this is a bit of an old post but I was having the same problem searching for a file. I did everything that was mentioned above and the script worked beatifully searching from "C:\" I had to make a few changes on my PC with regards to reinstalling some software and now I am getting the error

Invalid file handle used.:

$N_FILE = FileFindNextFile($N_SEARCH)

I tried reinstalling AutoIt and SciTe but that did not help. Any suggestions?

Share this post


Link to post
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
Sign in to follow this  
Followers 0