English
Forum

Question of the Week!

 

Frank
Abbing
Perhaps is so one Thread time nice. Someone asks a programming task and the rest trying to find a short and good solution...
The best solution would be put to the code snippets.

My task for today is:

Find a short and fast Solution to determine, if a directory is empty or not!
 
08/25/08  
 




Rolf
Koch
Mach time whom beginning make. naturally only secular nature

And from the length I find it personally still in order, I very highly compressed codes leseunfreundlich find ^^
CompileMarkSeparation
cls

proc isdirempty

    parameters dir$

    if direxists(dir$)

        if len(dir$) > 3

            clearList
            chdir dir$
            addFiles *"*.*"
            case %GetCount = -1:return 1
            chdir $ProgDir

        else

            return 3

        endif

    else

        return 2

    endif

endproc

Isdirempty "C:"
case %(0) = 0: print "Verzeichnis voll"
case %(0) = 1: print "Verzeichnis leer"
case %(0) = 2: print "Verzeichnis nicht gefunden"
case %(0) = 3: print "Root nicht möglich - bääätsch"
waitinput
 
08/25/08  
 




Jörg
Sellmeyer
the falls me to a. is longer but faster. Turnaround times for example, Rolfs C.: on, then is first Waiting angesagt. Also should return to ursprüngliche Directory to be changed.
CompileMarkSeparation
Proc DirIsEmpty

    Parameters Dir$
    Declare Dir1$
    CaseNot DirExists(Dir$):Return -1
    Dir1$ = GetDir$("@")
    ChDir Dir$

    If (Len(Dir$) <= 3) = 0

        FindFirst$("*")
        FindNext$()
        Dir$ = FindNext$()

    Else

        Dir$ = FindFirst$("*")

    EndIf

    ChDir Dir1$
    Return Len(Dir$) = 0

EndProc

Declare Ausgabe$
Ausgabe$ = "qnicht vorhanden!q,qnicht leerq,qleerq"
Print "C:XXXXX ist " + SubStr$(Ausgabe$,DirIsEmpty("C:XXXXX") + 2,",")
MkDir "C:XXXXX"
Print "C:XXXXX ist " + SubStr$(Ausgabe$,DirIsEmpty("C:XXXXX") + 2,",")
Assign #1,"Test.txt"
ReWrite #1
Print #1,"Test"
Close #1
Print "C:XXXXX ist " + SubStr$(Ausgabe$,DirIsEmpty("C:XXXXX") + 2,",")
Erase "C:XXXXXTest.txt"
RMDir "C:XXXXX"
' das Löschen funktioniert bei mir nicht - keine Ahnung warum
' liegts am System oder an Profan?
' also gegebenenfalls von Hand löschen
Print $Winpath + " ist " + SubStr$(Ausgabe$,DirIsEmpty($winpath) + 2,",")
Print "C: ist " + SubStr$(Ausgabe$,DirIsEmpty("C:") + 2,",")
WaitInput

Edit: ne still small correction applied!
 
Windows XP SP2 XProfan X4
... und hier mal was ganz anderes als Profan ...
08/25/08  
 




Rolf
Koch
back in that old directory? Jo haste full right
But the root C:?? Should always be something drinne

Edit: Habs also adapted. Determined as still missing what, but yes should also be short ^^
C: E: and Co are indeed not directly drives and directories, or I see it wrong?
 
08/25/08  
 



Can we look at "performantestes Beispiel" some?
 
08/26/08  
 




Jörg
Sellmeyer

C: E: and Co are indeed not directly drives and directories, or I see it wrong?


you know never, what a user of your program. Something like must But we are definitely. Also glite the same for deeply nested directories. I had folder structures with 20 - 30000 Files and subfolders hundreds. 'll Ask people with 'ner large mp3-collection how to feel, if you empty folder with a program tracking want and at first at each check 10 min coffee break is announced.
 
Windows XP SP2 XProfan X4
... und hier mal was ganz anderes als Profan ...
08/26/08  
 



Especially when not even no coffee in the house!
 
08/26/08  
 



Certainly no other provisos Frank?

A directory is a folder, So a list - not equal to any arbitrary path - and c: Although a path, but not a folder.

A performant way with XProfan, to determine, if a directory is empty, could therefore be the examination, if the directory can Delete.
CompileMarkSeparation
An exception for the root of a drive can be installed as easily, imho is not the task.
 
08/26/08  
 




Jörg
Sellmeyer
Delete, to determine, whether it is there? But this is the absolute sledgehammer.
 
Windows XP SP2 XProfan X4
... und hier mal was ganz anderes als Profan ...
08/26/08  
 



No, whether it is empty. The previous versions require a lot more load, however, these variants are therefore jackhammer. (Then dear Holzhammer... )
 
08/26/08  
 




Dieter
Zornow

CompileMarkSeparation
Def PathIsDirectoryEmpty(1) ! "shlwapi","PathIsDirectoryEmptyA"'gibt 1 für leer 0 für nein

proc isDirEmpty

    parameters dir$
    Return PathIsDirectoryEmpty(addr(dir$))

endp
>
 
Er ist ein Mann wie ein Baum. Sie nennen ihn Bonsai., Win 7 32 bit und Win 7 64 bit, mit XProfan X2
08/26/08  
 



My version is so cheese because it requires write access and also probably from a release as well as other attributes, Dieter was now just posting the faster I rauskrahmte Api...

Hrm, nevertheless: PathIsDirectoryEmpty
 
08/26/08  
 




Answer


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

25.177 Views

Untitledvor 0 min.
p.specht05/22/13
mene12/06/12
Peter Max Müller12/11/11
Jens Tiburski12/29/10
More...

Themeninformationen



Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie