a6m1n0 Posted September 15, 2005 Posted September 15, 2005 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
a6m1n0 Posted September 15, 2005 Author Posted September 15, 2005 Thanks for the tips Larry...I'll do that.
a6m1n0 Posted September 15, 2005 Author Posted September 15, 2005 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 :$ )
seandisanti Posted September 15, 2005 Posted September 15, 2005 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)
a6m1n0 Posted September 15, 2005 Author Posted September 15, 2005 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.
seandisanti Posted September 15, 2005 Posted September 15, 2005 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?
a6m1n0 Posted September 17, 2005 Author Posted September 17, 2005 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.htmThis 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 usedLine 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.
Digetal Posted September 17, 2005 Posted September 17, 2005 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
a6m1n0 Posted September 17, 2005 Author Posted September 17, 2005 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
Digetal Posted September 17, 2005 Posted September 17, 2005 I downloaded the script and tested it using winxp and autoit v3.1.1.75 (beta) and it workschangeDim $DIR="c:\winutil\autoit3\programs\test" ; specify the directory to searchtoDim $DIR="c:\" ; specify the directory to searchrun in beta run mode from sciteit does reply alot of files in my case 1,432and was giving the directories of each in a message boxohh, and you have to open scite and goto tools beta runcan't just click and run script doesn't workto complie use bet complie for scite
a6m1n0 Posted September 17, 2005 Author Posted September 17, 2005 (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. Edited September 17, 2005 by a6m1n0
a6m1n0 Posted September 17, 2005 Author Posted September 17, 2005 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.
Slydder Posted January 5, 2006 Posted January 5, 2006 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. HelloI 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 errorInvalid file handle used.: $N_FILE = FileFindNextFile($N_SEARCH) I tried reinstalling AutoIt and SciTe but that did not help. Any suggestions?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now