Jump to content

_GetFileList with multiple masks... is it possible?


Recommended Posts

I have a script running GetFileList that successfully pulls mp3's from my music folder. However i dont just wanna limit it to .mp3's. Is it possible to use more than one filemask in the function. I've tried creating a second getfilemask function, changing all the variable names and it didnt pull the files.

;-- set up global varibles
Global $rr_ini_file = "C:\Program Files\Road Runner\rr.ini"
Global $winamppath, $filepathread, $musicpath, $playlistpath, $DIR
Dim $FILES
Dim $DIR                        ; directory later specified by rr.ini
Dim $FILEMASK="*.mp3"                ; specify the filemask
;-- func call
Get_Paths()
$DIR=$musicpath

If $playlistpath= "0" Then
    $filepath = $musicpath
Else
    $filepath = $filepathread
ENDif
$playlistfile=($filepath&"new hits.m3u")
FileDelete($playlistfile)


$FILES = _GetFileList($DIR, $FILEMASK)
For $X = 0 To UBound($FILES)-1
    Get_date()
Next
Exit

;Remove_old()
;********************************************************************************
;Recursive search for filemask
;********************************************************************************

Func _GetFileList($T_DIR,$T_MASK)
   Dim $N_DIRNAMES[200000]; max number of directories that can be scanned
   Local $N_DIRCOUNT = 0
   Local $N_FILE
   Local $N_SEARCH
   Local $N_TFILE
   Local $N_OFILE
   Local $T_FILENAMES
   Local $T_FILECOUNT
   Local $T_DIRCOUNT = 1
  ; remove the end \ If specified
   If StringRight($T_DIR,1) = "\" Then $T_DIR = StringTrimRight($T_DIR,1)
   $N_DIRNAMES[$T_DIRCOUNT] = $T_DIR
  ; Exit if base dir doesn't exists
   If Not FileExists($T_DIR) Then Return 0
  ; keep on looping until all directories are scanned
   While $T_DIRCOUNT > $N_DIRCOUNT
      $N_DIRCOUNT = $N_DIRCOUNT + 1
     ; find all subdirs in this directory and save them in a array
      $N_SEARCH = FileFindFirstFile($N_DIRNAMES[$N_DIRCOUNT] & "\*.*") 
      While 1
         $N_FILE = FileFindNextFile($N_SEARCH)
         If @error Then ExitLoop
        ; skip these references
         If $N_FILE = "." Or $N_FILE = ".." Then ContinueLoop
         $N_TFILE = $N_DIRNAMES[$N_DIRCOUNT] & "\" & $N_FILE
        ; if Directory than add to the list of directories to be processed
         If StringInStr(FileGetAttrib( $N_TFILE ),"D") > 0 Then
            $T_DIRCOUNT = $T_DIRCOUNT + 1
            $N_DIRNAMES[$T_DIRCOUNT] = $N_TFILE
         EndIf
      Wend
      FileClose($N_SEARCH)
     ; find all Files that mtach the MASK
      $N_SEARCH = FileFindFirstFile($N_DIRNAMES[$N_DIRCOUNT] & "\" & $T_MASK ) 
      If $N_SEARCH = -1 Then ContinueLoop
      While 1
         $N_FILE = FileFindNextFile($N_SEARCH)
         If @error Then ExitLoop
        ; skip these references
         If $N_FILE = "." Or $N_FILE = ".." Then ContinueLoop
         $N_TFILE = $N_DIRNAMES[$N_DIRCOUNT] & "\" & $N_FILE
        ; if Directory than add to the list of directories to be processed
         If StringInStr(FileGetAttrib( $N_TFILE ),"D") = 0 Then
            $T_FILENAMES  = $T_FILENAMES & $N_TFILE & @CR
            $T_FILECOUNT = $T_FILECOUNT + 1
           ;MsgBox(0,'filecount ' & $T_FILECOUNT ,$N_TFILE)
         EndIf
      Wend
      FileClose($N_SEARCH)
   Wend
   $T_FILENAMES  = StringTrimRight($T_FILENAMES,1)
   $N_OFILE = StringSplit($T_FILENAMES,@CR)
   Return( $N_OFILE )
EndFunc  ;==>_GetFileList2









Func Get_date()
    $t=filegettime($FILES[$X],1)
    if not @error then
        $date= $t[2]
        $month= $t[1]
        $year= $t[0]
        if $year= @YEAR then
            if $month = @mon then 
                if $date <= @mday Then
                    filewriteline($filepath&"new hits.m3u",$FILES[$x])
                Else
                EndIf
            Else
                if $month = (@mon-1) Then
                    if $date >= @mday Then
                    filewriteline($filepath&"new hits.m3u",$FILES[$x])
                    Else
                    EndIf
                Else
                endif
            EndIf
        Else
            if $year = (@year-1) Then
                if $month=12 then filewriteline($filepath&"new hits.m3u",$FILES[$x])
            Endif
        EndIf
    endif
EndFunc

Func Get_Paths();blue zx3's addition
;==================================================================
;=== get playlistpath form rr.ini
;==================================================================
    $num_entery = _FileCountLines($rr_ini_file)+1
    $ln=1
    Do
        $var = FileReadLine($rr_ini_file,$ln)
        $ln = $ln + 1   
        If StringInStr($var,"winamppath=") Then $winamppath = StringMid($var,12)
        If StringInStr($var,"playlistpath=") Then $filepathread = StringMid($var,14)
        If StringInStr($var,"musicpath=") Then $musicpath = StringMid($var,11)
    Until $ln = $num_entery 
EndFunc

Func _FileCountLines($sFilePath)
    Local $N = FileGetSize($sFilePath) - 1
    If @error Or $N = -1 Then Return 0
    Return StringLen(StringAddCR(FileRead($sFilePath, $N))) - $N + 1
EndFunc  ;==>_FileCountLines
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...