Sign in to follow this  
Followers 0

list all avi files inDir and all avi's in subDirs

4 posts in this topic

Hi i would like to know how would i list all .avi's that are in a folder and then list all the .avi's that are in the sub folders.

Share this post

Link to post
Share on other sites

#2 ·  Posted (edited)

Try to take some time out of your very busy life and think how you can find the answers you want.

Search the forums for file searching code. It's there. I'd know because I made one. Others have done it too.

It's even displayed on the very first page of this section of the forum (as of time of posting).

Edited by omikron48

Share this post

Link to post
Share on other sites


#include <array.au3> ; include is only needed for _ArrayDisplay ()
;Start Folder
$dir = @DesktopDir
$arfolder = _GetFilesFolder_Rekursiv($dir, "avi", 0)
_ArrayDisplay ($arfolder) ; see above

; Function Name:   _GetFilesFolder_Rekursiv($sPath [, $sExt='*' [, $iDir=-1 [, $iRetType=0 ,[$sDelim='0']]]])
; Description:     recursive listing of files and/or folders
; Parameter(s):    $sPath     Basicpath of listing ('.' -current path, '..' -parent path)
;                  $sExt      Extension for file selection '*' or -1 for all (Default)
;                  $iDir      -1 Files+Folder(Default), 0 only Files, 1 only Folder
;      optional:   $iRetType  0 for Array, 1 for String as Return
;      optional:   $sDelim    Delimiter for string return
;                             0 -@CRLF (Default)  1 -@CR  2 -@LF  3 -';'  4 -'|'
; Return Value(s): Array (Default) or string with found pathes of files and/or folder
;                  Array[0] includes count of found files/folder
; Author(s):       BugFix (
Func _GetFilesFolder_Rekursiv($sPath, $sExt='*', $iDir=-1, $iRetType=0, $sDelim='0')
    Global $oFSO = ObjCreate('Scripting.FileSystemObject')
    Global $strFiles = ''
    Switch $sDelim
        Case '1'
            $sDelim = @CR
        Case '2'
            $sDelim = @LF
        Case '3'
            $sDelim = ';'
        Case '4'
            $sDelim = '|'
        Case Else
            $sDelim = @CRLF
    If ($iRetType < 0) Or ($iRetType > 1) Then $iRetType = 0
    If $sExt = -1 Then $sExt = '*'
    If ($iDir < -1) Or ($iDir > 1) Then $iDir = -1
    If $iRetType = 0 Then
        Local $aOut
        $aOut = StringSplit(StringTrimRight($strFiles, StringLen($sDelim)), $sDelim, 1)
        If $aOut[1] = '' Then
            ReDim $aOut[1]
            $aOut[0] = 0
        Return $aOut
        Return StringTrimRight($strFiles, StringLen($sDelim))

Func _ShowSubFolders($Folder, $Ext='*', $Dir=-1, $Delim=@CRLF)
    If Not IsDeclared("strFiles") Then Global $strFiles = ''
    If ($Dir = -1) Or ($Dir = 0) Then
        For $file In $Folder.Files
            If $Ext <> '*' Then
                If StringRight($file.Name, StringLen($Ext)) = $Ext Then _
                    $strFiles &= $file.Path & $Delim
                $strFiles &= $file.Path & $Delim
    For $Subfolder In $Folder.SubFolders
        If ($Dir = -1) Or ($Dir = 1) Then $strFiles &= $Subfolder.Path & '\' & $Delim
        _ShowSubFolders($Subfolder, $Ext, $Dir, $Delim)



Share this post

Link to post
Share on other sites

#4 ·  Posted (edited)

This works, too, and is much more compact then 99ojo's code. Perhaps his has more functionality, but this does exactly what you want:

#include <Array.au3>

Dim $aviFiles[1]
ScanDir(@ScriptDir, "avi", $aviFiles) ; Scans @ScriptDir & subdirectories for .avi files

Func ScanDir($hDir, $ext, ByRef $arr)
  $hSearch = FileFindFirstFile("*.*")
  $hFile = FileFindNextFile($hSearch)
  While Not @error
    If @extended Then ; $hFile is a directory
      ScanDir($hDir & "\" & $hFile, $ext, $arr) ; Scan the subdirectory for .avi files
    Else ; $file is een file
      If StringRegExp($hFile, "(?i)\." & $ext & "\z") Then _ArrayAdd($arr, $hDir & "\" & $hFile) ; Add file to array
    $hFile = FileFindNextFile($hSearch)

The array is 1 based, index 0 is empty.

Edited by d4ni

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