Login Register
Frontpage Code library Pastebin

FindFile

Author: Jonhux
Added: 27. elokuuta 2011 kello 10.21
Edited: 27. elokuuta 2011 kello 10.22
Category: Tiedostot

Description

Ohjelma etsii tiedostot haluamastasi hakemistosta ja sen alahakemistoista.

Code

Select all
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Jonhu 25.8.2011

Type FOLDERLIST
    Field s$
EndType

n = FindFiles( "C:\Program Files\CoolBasic" ) //CurrentDir() )
Print ""
Print "==== Ready ===="
Print n + " Files Found"
WaitKey

Function FindFiles( position$, format$ = ".bmp" )
    count = 0
    aa.FOLDERLIST = New (FOLDERLIST)
    aa\s = position$
    pos$ = CurrentDir()
    
    For aa.FOLDERLIST = Each FOLDERLIST
        
        ChDir ""+aa\s
        StartSearch
            Repeat
                file$=FindFile()
                If file$="" Then Exit //no more files
                If file$ <> "." And file$ <> ".." Then
                    If IsDirectory(file$) Then // if folder
                        a.FOLDERLIST = New(FOLDERLIST)
                        a\s = CurrentDir()+file$
                    
                    ElseIf Lower(Right(file$, Len(format) ) ) = format Then // if file
                        Print file$
                        count = count + 1
                    EndIf
                EndIf
            Forever
        EndSearch
        Delete aa
    Next aa
    
    ChDir ""+pos$ // return to start position
    Return count
EndFunction

Comments

No comments. You can be first!

Leave a comment

You must be logged in to comment.