[R] Nombre de fichiers dans un dossier
Posté : dim. 04 nov. 2007 01:56
Salut à tous !
Voilà, je cherche le moyen de lister les fichiers d'un dossier, et si le résultat est différent de 1 : le dossier est détruit.
Le tout automatiquement.
Ou comment faire une fonction autonome avec _FileListToArray par exemple (ou autre...)
Sans utiliser #include <File> et #include <Array> (pour ne pas alourdir le script) car cela ne concerne que un dossier et un type de fichier.
J'ai pas mal cherché sur les forums et le net, mais je n'arrive pas à mettre en place ce que je veux (là, je suis dépassé !) à partir de ce que j'ai trouvé :
[autoit]$dossier = @homepath
$FileList = _FileListToArray ( $dossier , " *.* " , 1 ) ; 0 = fichier et dossier / 1 = fichier / 2 = dossier
If @Error = 1 Then
MsgBox ( 0 , " " , " Aucun fichier trouvé. " )
Exit
EndIf
for $i = 1 to $FileList[0]
next
msgbox ( 0 , " Information " , $dossier & @cr & " Contient exactement : " & $filelist[0] & " fichier " , 5 )
; == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
$rep = " "
$rep = InputBox ( " Information " , " Indiquer le répertoire c: " , $rep )
dossier_rep ( $rep )
Func dossier_rep ( $rep )
$FileList = _FileListToArray ( $rep , " *.* " , 1 ) ; 0 = fichier et dossier / 1 = fichier / 2 = dossier
If @Error = 1 Then
MsgBox ( 0 , " " , " Aucun fichier trouvé. " )
Exit
EndIf
for $i = 1 to $FileList[0]
next
msgbox ( 0 , " Information " , $rep & @cr & " Contient exactement : " & $filelist[0] & " fichier " , 5 )
EndFunc
; == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
Func _FileListToArray ( $sPath , $sFilter = " * " , $iFlag = 0 )
Local $hSearch , $sFile , $asFileList[1]
If Not FileExists ( $sPath ) Then Return SetError ( 1 , 1 , " " )
If ( StringInStr ( $sFilter , " \ " ) ) Or ( StringInStr ( $sFilter , " / " ) ) Or ( StringInStr ( $sFilter , " : " ) ) Or ( StringInStr ( $sFilter , " > " ) ) Or ( StringInStr ( $sFilter , " < " ) ) Or ( StringInStr ( $sFilter , " | " ) ) Or ( StringStripWS ( $sFilter , 8 ) = " " ) Then Return SetError ( 2 , 2 , " " )
If Not ( $iFlag = 0 Or $iFlag = 1 Or $iFlag = 2 ) Then Return SetError ( 3 , 3 , " " )
$hSearch = FileFindFirstFile ( $sPath & " \ " & $sFilter )
If $hSearch = - 1 Then Return SetError ( 4 , 4 , " " )
While 1
$sFile = FileFindNextFile ( $hSearch )
If @error Then
SetError ( 0 )
ExitLoop
EndIf
If $iFlag = 1 And StringInStr ( FileGetAttrib ( $sPath & " \ " & $sFile ) , " D " ) <> 0 Then ContinueLoop
If $iFlag = 2 And StringInStr ( FileGetAttrib ( $sPath & " \ " & $sFile ) , " D " ) = 0 Then ContinueLoop
ReDim $asFileList[UBound ( $asFileList ) + 1]
$asFileList[0] = $asFileList[0] + 1
$asFileList[UBound ( $asFileList ) - 1] = $sFile
WEnd
FileClose ( $hSearch )
Return $asFileList
EndFunc[/autoit]
Peut-être que c'est tout simple, mais là je crois qe j'ai atteint mes limittes en matière de programmation AutoIt.
Merci d'avance et...
Bon Vent !
Tragan
Voilà, je cherche le moyen de lister les fichiers d'un dossier, et si le résultat est différent de 1 : le dossier est détruit.
Le tout automatiquement.
Ou comment faire une fonction autonome avec _FileListToArray par exemple (ou autre...)
Sans utiliser #include <File> et #include <Array> (pour ne pas alourdir le script) car cela ne concerne que un dossier et un type de fichier.
J'ai pas mal cherché sur les forums et le net, mais je n'arrive pas à mettre en place ce que je veux (là, je suis dépassé !) à partir de ce que j'ai trouvé :
[autoit]$dossier = @homepath
$FileList = _FileListToArray ( $dossier , " *.* " , 1 ) ; 0 = fichier et dossier / 1 = fichier / 2 = dossier
If @Error = 1 Then
MsgBox ( 0 , " " , " Aucun fichier trouvé. " )
Exit
EndIf
for $i = 1 to $FileList[0]
next
msgbox ( 0 , " Information " , $dossier & @cr & " Contient exactement : " & $filelist[0] & " fichier " , 5 )
; == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
$rep = " "
$rep = InputBox ( " Information " , " Indiquer le répertoire c: " , $rep )
dossier_rep ( $rep )
Func dossier_rep ( $rep )
$FileList = _FileListToArray ( $rep , " *.* " , 1 ) ; 0 = fichier et dossier / 1 = fichier / 2 = dossier
If @Error = 1 Then
MsgBox ( 0 , " " , " Aucun fichier trouvé. " )
Exit
EndIf
for $i = 1 to $FileList[0]
next
msgbox ( 0 , " Information " , $rep & @cr & " Contient exactement : " & $filelist[0] & " fichier " , 5 )
EndFunc
; == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
Func _FileListToArray ( $sPath , $sFilter = " * " , $iFlag = 0 )
Local $hSearch , $sFile , $asFileList[1]
If Not FileExists ( $sPath ) Then Return SetError ( 1 , 1 , " " )
If ( StringInStr ( $sFilter , " \ " ) ) Or ( StringInStr ( $sFilter , " / " ) ) Or ( StringInStr ( $sFilter , " : " ) ) Or ( StringInStr ( $sFilter , " > " ) ) Or ( StringInStr ( $sFilter , " < " ) ) Or ( StringInStr ( $sFilter , " | " ) ) Or ( StringStripWS ( $sFilter , 8 ) = " " ) Then Return SetError ( 2 , 2 , " " )
If Not ( $iFlag = 0 Or $iFlag = 1 Or $iFlag = 2 ) Then Return SetError ( 3 , 3 , " " )
$hSearch = FileFindFirstFile ( $sPath & " \ " & $sFilter )
If $hSearch = - 1 Then Return SetError ( 4 , 4 , " " )
While 1
$sFile = FileFindNextFile ( $hSearch )
If @error Then
SetError ( 0 )
ExitLoop
EndIf
If $iFlag = 1 And StringInStr ( FileGetAttrib ( $sPath & " \ " & $sFile ) , " D " ) <> 0 Then ContinueLoop
If $iFlag = 2 And StringInStr ( FileGetAttrib ( $sPath & " \ " & $sFile ) , " D " ) = 0 Then ContinueLoop
ReDim $asFileList[UBound ( $asFileList ) + 1]
$asFileList[0] = $asFileList[0] + 1
$asFileList[UBound ( $asFileList ) - 1] = $sFile
WEnd
FileClose ( $hSearch )
Return $asFileList
EndFunc[/autoit]
Peut-être que c'est tout simple, mais là je crois qe j'ai atteint mes limittes en matière de programmation AutoIt.
Merci d'avance et...
Bon Vent !
Tragan