Sign in to follow this  
Followers 0
d4rk

_DirGet UDFs

1 post in this topic

#1 ·  Posted (edited)

Hello,i've written this since seeing some questions like "are there any shortest way to count all files in a folder" , "is it possible to know file's attributes in a folder" ... i know that all can do but it's better making a short , simple one UDF to solve the problem, but later i found that it's much better than i expected...

In developing : accept files with the following type "ASH","HND",...

hope it's helpful

_DirGet()

$Path : Path of folder

$Filter : File type (*.* for all files)

$Flag : [0 - both files and folders] [1 - Files only] [2- Folder only]

$Status :

"R" = READONLY

"A" = ARCHIVE

"S" = SYSTEM

"H" = HIDDEN

"N" = NORMAL

"O" = OFFLINE

"T" = TEMPORARY

*$Path,$Filter,$Flag are the same describe as _FileListToArray()

*$Status are the same describe as FileSetAttrib

;||----------------------------------------------------------||
;||----------------------------------------------------------||
;||Function _DirGet()          
;||Syntax:  _DirGet($Path="",$Filter="",$Flag=0,$Status="")
;||Requirement(s):   <Array.au3><File.au3>
;||On Success : Return Dir's Files Summary
;||On Fail : Exit script                                     
;||Author : d4rk < Le Khuong Duy >               
;||----------------------------------------------------------||
;||----------------------------------------------------------||
#include <File.au3>
#include <Array.au3>
Func _DirGet($Path="",$Filter="",$Flag=0,$Status="")
Dim $Total,$Count
$Chars=_ArrayCreate("R","A","S","H","N","D","O","C","T","")
For $j=0 to UBound($Chars)-1
if $Status<>$Chars[$j] Then
$Count=$Count+1
Else
EndIf
Next

if $Count=10 Then
    ConsoleWrite("_DirGet Call with wrong attribute ")
    Exit
EndIf
;------------------------
If $Path="" Then
    $Path=@ScriptDir & "\"
Else
    $Path=$Path
EndIf
;------------------------
If $Filter="" Then
    $Filter="*.*"
Else
    $Filter=$Filter
EndIf
;------------------------
If $Status="" Then
$Files=_FileListToArray($Path,$Filter,$Flag)
$Bound=UBound($Files)-1
Return $Bound
EndIf

$Files=_FileListToArray($Path,$Filter,$Flag)
For $i=1 to UBound($Files)-1
    $GetStatus=FileGetAttrib($Path & $Files[$i])
    If StringInStr($GetStatus,$Status) Then
    $Total=$Total+1
EndIf
Next
Return $Total
EndFuncoÝ÷ ØLZ^jëh×6MsgBox(64,"",_DirGet("","","","")); Get all files in the current dir
MsgBox(64,"",_DirGet("","*.au3","","")); Get all au3 files in the current dir
MsgBox(64,"",_DirGet("","*.*","","H")); Get all hidden files in the current dir

For download lover :

DirGet.au3

Edited by d4rk

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

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