Jump to content

Using FileFindNextFile


 Share

Recommended Posts

using FileExists as it does a directory or file check.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

using FileExists as it does a directory or file check.

There are many implementations shown on this forum, use the search function. The short answer is to check each return to see if it's a directory, that is if it has the file attribute D, and then treat it as a directory (dig in and search more).
Link to comment
Share on other sites

#include <Array.au3>

Dim $aFullPath[100]
Global $iFiles, $iFolders, $iCount = 0

_SearchEx(@DesktopDir, $aFullPath, '*.*')
_ArrayDisplay($aFullPath, $iFiles & ' Files, ' & $iFolders & ' Folders')

Func _SearchEx($sSourcePath, ByRef $aFileList, $sExt = '*.*', $iRunFirstTime = 1)
    If UBound($aFileList) < 10000 Then ReDim $aFileList[10000]
    If StringRight($sSourcePath, 1) = '\' Then $sSourcePath = StringTrimRight($sSourcePath, 1)

    $sExt = StringReplace($sExt, '\', '')
    $iFirstFile = FileFindFirstFile($sSourcePath & '\' & $sExt)
    If @error Then Return

    While 1
        $iNextFile = FileFindNextFile($iFirstFile)
        If @error Then ExitLoop
            
        $sFullPath = $sSourcePath & '\' & $iNextFile
        If StringInStr(FileGetAttrib($sFullPath), "D") Then
            $iFolders += 1
            _SearchEx($sFullPath, $aFileList, $sExt, 0)
        Else
            $iFiles += 1
            $iCount += 1
            If $iCount = 10000 Then
                ReDim $aFileList[UBound($aFileList) + 10000]
                $iCount = 0
            EndIf
            $aFileList[$iFiles] = $sFullPath
        EndIf               
    WEnd
    
    FileClose($iFirstFile)
    If $iRunFirstTime Then 
        ReDim $aFileList[$iFiles + 1]
        $aFileList[0] = UBound($aFileList) - 1
    EndIf
EndFunc

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

Hey few weeks ago i developed a script similar to this.. this checks every folder in every drive of the system for files with a specific extension:

#include<Array.au3>
#include<File.au3>
#include-once
#RequireAdmin
$mFile = FileOpen("Images.txt", 2) 
$var = DriveGetDrive( "FIXED" )
local $uArray, $iStdoutg, $sTemp, $placeholder,$sFolder,$tSort
    For $i = 1 to $var[0]
    $gFolder=($var[$i]&"/*.gho"); specify any file extension here
    $pFolder=($var[$i]&"/*.pqi"); specify any file extension here
    Search($gfolder)
    Search($pfolder)
Next
FileClose($mFile)

Func Search($var)
    $iStdoutg = Run(@comspec & ' /C cd ..\..\..\..\.. & dir "' & $var& '" /A /B /O:' & $tSort & ' /S', @workingdir, _
            @SW_HIDE, 6)
While 1
        $line = StdoutRead($iStdoutg)
        If @error Then ExitLoop
        If $line <> "" then 
            FileWriteLine($mFile,$line)
        EndIf
Wend
EndFunc

Maybe it may help u??

Edited by Manjish
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
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...