Jump to content
Sign in to follow this  
patk

FileFindFirstFile returns -1 when files are present

Recommended Posts

patk

I am using FileFindFirstFile to get a list of all folders/files in C:\Documents and Settings\ This works on a number of computers that I get files off of but there are certain computers that it fails on. One that I was able to ask info about had a large number of users on it making many folders in documents and settings. I believe this is the cause of FileFindFirstFile returning -1 and not giving me the folders to grab files from. Here is the code I am using to accomplish this.

$src = "\\" & $compname & "\" & $partofdir  ;partofdir=C$\Documents and Settings\
;find all files that can fit, checks all users and finds files
$sPath=$src
LogError($nm, "Searching "&$sPath & "\*")
$hSearch = FileFindFirstFile($sPath & "\*")
If $hSearch <> -1 Then
    LogError($nm, "Search found folders"); does not get to this point on certain computers
    While 1
    ;get folder from search
        $sFile = FileFindNextFile($hSearch)
        If @error Then
            ExitLoop
        EndIf
    ;check if a directory
        If StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then ContinueLoop
        LogError($nm, "Searching folder "&$sFile)
    ;search for file in folder
        $search = FileFindFirstFile($src & $sFile &"\Application Data\somefile.txt")
        If $search <> -1 Then
            While 1
            ;get the file name from the search
                $file = FileFindNextFile($search)
                If @error Then ExitLoop;if there is an error then end the loop, usually due to no more files found
            ;..... code to do things with the files
            WEnd
        EndIf
    ; Close the search handle
        LogError($nm, "Done searching folder "&$sFile)
        FileClose($search)
        WEnd
Else
    LogError($nm, "Search error "&@error)
EndIf
FileClose($hSearch)
LogError($nm, "Done copying from this computer")

As I said this works on just about all of the computers it goes to but there are some with large numbers of users and it returns -1 and @error = 0

I have tried using _FILELISTTOARRAY but it would simply freeze when it got to one of the computers with many users. I then tried filelisttoarray3 which had same results. The only reason I can think that it returns -1 is if it is trying to read too many files into the search handle. I am open to suggestions of all sorts, let me know what you think or if there is another way to do this that will work.

Share this post


Link to post
Share on other sites
LarryDalooza

Also, consider the OS and possible permissions issues.

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites
patk

It is a windows xp machine and I have full Admin privileges

Share this post


Link to post
Share on other sites
Jos

shouldn't this : $hSearch = FileFindFirstFile($sPath & "\*")

be: $hSearch = FileFindFirstFile($sPath & "*")

?


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
patk

yes, it was a bad copy paste job, $sPath actually did not have the ending \ but it would work even if there were two \\ it will still find the files properly on the other computers

Share this post


Link to post
Share on other sites
patk

Does anyone have any ideas on what may cause this? I tried finding the function's file so I can edit it to make it work but I was unable to find where it was located, I am assuming it is built into something somewhere that is encrypted so I can't change it or find it.

The folder is guaranteed to have something in it no matter what so why does it not find anything?

Share this post


Link to post
Share on other sites
patk

sigh... I am still unable to find a work around for this issue, should I post it as a bug seeing as no one has an answer or suggestion?

Share this post


Link to post
Share on other sites
PsaltyDS

sigh... I am still unable to find a work around for this issue, should I post it as a bug seeing as no one has an answer or suggestion?

Only submit a ButTrac if you can post code that will reproduce the error for whoever runs it. If it is dependent on the particular configuration of particular computers, then it is not an AutoIt problem.

For example. Just because you are an Admin does not automatically give you access to other user's directories unless you are willing to take ownership/replace permissions, etc. Such things are more likely to be the problem than an old, stable, well tested AutoIt function.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.