Jump to content

Dir command like dos ?


arcker
 Share

Recommended Posts

Hi evry1, My boss want a script that shows the directorories that exceeds a defined size

here the code in batch (it works well)

@echo off
set max=50
set lect=f:
set chemin=batch\alsi\eleves
set fichlog=%0.log
set reptravail=f:\batch\alsi\eleves
set replog=%reptravail%\log
set filtredossier=?34*.*
set fichtmp=%reptravail%\%0.txt
set fichtmp2=%reptravail%\%0ELEVES.txt

dir /b /a:d f:\batch\alsi\eleves >%fichtmp%
:ANALYSE
echo -- verification des quotas (max. %max% Mo)
echo.
FOR /F %%A IN (%fichtmp%)do (
        dir /b /a:d f:\batch\alsi\eleves\%%A >%fichtmp2%
        FOR /F %%B IN (%fichtmp2%) do (
            set Queleleve=%%B
            set Quelclasse=%%A
            diruse /d /m /q:%max% %lect%\%chemin%\%%A\%%B
            if errorlevel 1 call :display ))
            
:rapport

goto fin
:display
echo [%queleleve%] dans la classe [%quelclasse%] depasse le quota (%max% Mo) !
echo [%queleleve%] dans la classe [%quelclasse%] depasse le quota (%max% Mo) ! >>%replog%\%fichlog%

so here the begining of the script in Autoit

$max=50
$lect="f:"
$chemin="batch\alsi\eleves"
$fichlog=%0.log
$reptravail="f:\batch\alsi\eleves"
$replog=$reptravail &"\log"
$filtredossier="?34*.*"
$fichtmp=$reptravail & "\essai.txt"
$fichtmp2=$reptravail & "\ELEVES.txt"

$fichtmp

$max= inputbox("verification des quotas","modifiez la valeur si besoin" & @crlf & "valeur en Mo " & $max & " Mo")
FileOpen ( $fichtmp, 10 )
FileOpen ( $fichtmp2, 10 )
FOR  $A IN $fichtmp
        dir /b /a:d f:\batch\alsi\eleves\%%A >%fichtmp2% <= the problem of translation !
        FOR  $B IN $fichtmp2
            $Queleleve=$B
            $Quelclasse=$A
            if DirGetSize( "path" ,0 ) >%max%
            call ("display")
                                                endif
        next     
next
            



Func display()
     msgbox( "Dépassement",$queleleve & " dans la classe " & $quelclasse " depasse le quota " & $max & " Mo")
         filewriteline($fichlog,"Dépassement",$queleleve & " dans la classe " 
         & $quelclasse " depasse le quota " & $max & " Mo")
EndFunc

so i need a command that stores the dir names in a file (or if you have another solution, it would be fine !)

to enumerate them and test them

thx again

c u

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

because i don't want to use any command in dos, if possible, or there is not interest in using another langage

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

Hi,

Here it is in vbscript; you could run this from a run command as a quick solution, knowing you can translate it to AutoIt soon!

Option Explicit

Dim objFileSystem: Set objFileSystem = CreateObject( "Scripting.FileSystemObject")

Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim objOutput:Set objOutput = objFileSystem.CreateTextFile( "C:\Program Files\AU3PROGS\Scite\Answer.txt", True )

Dim strCurrentFolder,strMask

Select Case WScript.Arguments.Count

Case 0: strCurrentFolder = objFSO.GetAbsolutePathName(".") ' list current directory

Case 1: strCurrentFolder = WScript.Arguments(0) ' list argument 1 directory

Case Else: WScript.Echo "Invalid number of arguments.": wscript.quit': Exit sub

End Select

if strMask = "" then strMask = "*.*"

Dim objFolder: Set objFolder = objFSO.GetFolder(strCurrentFolder)

IterateThroughDirectory objFolder

objOutput.Close

Sub IterateThroughDirectory(objFolder)

Dim objSubFolder

For Each objSubFolder in objFolder.SubFolders

objOutput.WriteLine objSubFolder

IterateThroughDirectory objSubFolder

Next

End Sub

Best, randall Edited by randallc
Link to comment
Share on other sites

yes felix, that's my question ! i don't want to use dos command, but i need dir !

thx for the help, i've found a first solution with filefindfirstfile

here is my script to show and log directories that exceeds a certain size :

$max=50
$fichlog="essai.log"
$reptravail="f:\batch\alsi\eleves"
$replog=$reptravail &"\log.log" 

       
        
$max= inputbox("verification des quotas","modifiez la valeur si besoin" & @crlf & "valeur en Mo ", $max)

$search = FileFindFirstFile("TE34*")  

If $search = -1 Then
    MsgBox(0, "Erreur", "Rien trouvé -_- dans ce répertoire")
EndIf


While 1
    $file = FileFindNextFile($search) 
     If @error Then ExitLoop
     
If round(dirgetsize($file)/1024/1024) >$max then
msgbox(0, "Dépassement",$file & " depasse le quota " & $max & " Mo")
filewriteline($replog, "Dépassement : " & $file &  " depasse le quota " & $max & " Mo")

endif    
WEnd

FileClose($search)

so now, i need :

1 - just search directories instead of all files

2 - go in the subdirectories, and search in it

=>i think the solution is with "filechangedir" and @workingdir, but it appears difficult

any ideas ?

thx a lot again

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

Hi, again1

Hard to know what you really want; here's the previous vbscript translated plus folder sizes; just FileRead "$AnswerFolder" and get your info?

Best, Randall

$s_AnswerFile=@ScriptDir&"\Answer.txt"

$s_AnswerFolders=@ScriptDir&"\AnswerFolders.txt"

FileDelete($s_AnswerFile)

FileDelete($s_AnswerFolders)

$i_ArrayToo=0

$s_Path="c:\"

$s_Path=FileSelectFolder("Choose a folder.",$s_Path,7,@ScriptDir)

$t = TimerInit()

$FoldersOnly=1; avoids full file find

;===============================================================

; SYNTAX; _DirFileListRecursive($s_Path,$s_AnswerFile,$s_AnswerFolders, $FoldersOnly); $FoldersOnly=1 isquicker if that is all you want

_DirFileListRecursive($s_Path,$s_AnswerFile,$s_AnswerFolders,$FoldersOnly)

;===============================================================

ConsoleWrite(Timerdiff($t) & @CRLF)

;RunWait("Notepad.exe " & $s_AnswerFile,@ScriptDir,@SW_SHOW)

RunWait("Notepad.exe " & $s_AnswerFolders,@ScriptDir,@SW_SHOW)

Exit

Func _DirFileListRecursive($strCurrentFolder,$s_AnswerFile,$s_AnswerFolders,$i_FoldersOnly)

$objFileSystem = ObjCreate( "Scripting.FileSystemObject")

$objOutFiles = $objFileSystem.CreateTextFile( $s_AnswerFile, 1 )

$objOutFolders = $objFileSystem.CreateTextFile( $s_AnswerFolders, 1 )

$objFolder = $objFileSystem.GetFolder($strCurrentFolder)

_IterateThroughDirectory ($objFolder,$objOutFiles,$objOutFolders,$i_FoldersOnly)

$objOutFiles.Close()

$objOutFolders.Close()

EndFunc ;==>_DirFileListRecursive

Func _IterateThroughDirectory($objFolder,$objOutFiles,$objOutFolders,$i_FoldersOnly)

if $i_FoldersOnly=0 then

For $objFile in $objFolder.Files()

$objOutFiles.WriteLine ($objFile.Path)

Next

EndIf

For $objSubFolder in $objFolder.SubFolders()

;$objOutFolders.WriteLine (StringReplace(($objSubFolder.Size&"\"&$objSubFolder.Path),"\",@tab))

$objOutFolders.WriteLine ($objSubFolder.Size&@tab&@TAB&$objSubFolder.Path)

_IterateThroughDirectory ($objSubFolder,$objOutFiles,$objOutFolders,$i_FoldersOnly)

Next

EndFunc ;==>_IterateThroughDirectory

Edited by randallc
Link to comment
Share on other sites

you're amazing guy, it's exactly what i need !

i'll try to adapt it in my script

thx a lot again

c u

is there any way to translate it more "autoit"

i have to prove to my boss that autoit 3 is a good langage B)

so the code is good, but look too "vbscript"

i'm trying to completely convert it, but i can't get trought the scripting file object, isn't it ?

Edited by arcker

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

FilefindFirst; Script showing usage Example below;( Beerman?)

RecursiveDir.au3

Randall

Then You should just modify Beerman script;

Best, randall

;;; RecursiveDir.au3 ;;;

#include-once

;

; the target folder will be recursively searched through

; and returns an array of files and folder together with full path.

; thanks in big part to Larry for the script which i modified

; useage : _Recursive($Sourcedir)

; please sectect only folders not drive letters by themselves.

; Beerman

$t = TimerInit()

FileDelete(@ScriptDir&"\OutputSubDirs.txt")

$Sourcedir=@ScriptDir

$outputsubdirs=_Recursive($Sourcedir)

;$var = _FileSearch($Sourcedir*"\*.*")

;For $i = 1 to $var[0];ConsoleWrite($var[$i] & @LF)

;Next

ConsoleWrite(Timerdiff($t) & @CRLF)

FileWrite(@ScriptDir&"\OutputSubDirs.txt",$outputsubdirs)

ConsoleWrite(Timerdiff($t) & @CRLF)

RunWait("Notepad.exe " & @ScriptDir&"\OutputSubDirs.txt",@ScriptDir,@SW_SHOW)

;------------------------------------------------------------------------------------

Func _Recursive($Sourcedir)

$a = 0

$f = 0

$d = 0

$grand = ""

While 1

$Fold = $Sourcedir

$reject = StringLen($Fold)

If $reject = 3 Then

MsgBox(0, 'Rejected', "This routine is only meant for folders only. Slect Again")

$dirrejected = FileSelectFolder("Choose a folder this time not a drive letter.", "")

If $dirrejected = "" Then Exit

$Sourcedir = $dirrejected

Else

$Stack = $Fold & ">"

$FileList = dirgetsize($Fold)& @TAB& @TAB&$Fold &@CRLF

While $Stack <> ""

$root = StringLeft($Stack, StringInStr($Stack, ">") - 1) & "\"

$Stack = StringTrimLeft($Stack, StringInStr($Stack, ">"))

$h = FileFindFirstFile($root & "*.*")

If $h > - 1 Then

$FileFound = FileFindNextFile($h)

While Not @Error And $FileFound <> ""

If $FileFound <> "." And $FileFound <> ".." And _

StringInStr(FileGetAttrib($root & $FileFound), "D") Then

$Stack = $Stack & $root & $FileFound & ">"

$FileList = $FileList &dirgetsize($FileFound)& @TAB& @TAB& $root & $FileFound & "<"

$d = $d + 1

$a = $a + 1

Else

;If $FileFound = "." Or $FileFound = ".." Then

;Else

;$f = $f + 1

;$a = $a + 1

;$FileList = $FileList & $root & $FileFound & "<"

;EndIf

EndIf

$len = StringLen($FileList)

If $len > 10000 Then

$grand = $grand & $FileList

$FileList = ""

Else

EndIf

ToolTip("Building List: Files-" & $f & " Folders-" & $d & " Total-" & $a, 0, 0)

$FileFound = FileFindNextFile($h)

WEnd

FileClose($h)

EndIf

WEnd

$grand = $grand & $FileList

$FileList = $grand

$cleanup = StringReplace($FileList, ">", "<")

;$outputsubdirs = StringSplit($cleanup, "<", 1)

$cleanup = StringReplace($FileList, "<", @CRLF)

;Return $outputsubdirs

Return $cleanup

Exit

EndIf

WEnd

EndFunc ;==>_Recursive

Edited by randallc
Link to comment
Share on other sites

this script is difficult to understand because of the string (i've not understood everything)

but, i've edited it and here mine

$max=5
$fichier=fileopen("rapport.txt",2)
msgbox(0,"", _Recursive("f:\batch"))


fileclose($fichier)

Func _Recursive($repertoiresource)
    
    $a = 0
    $f = 0
    $d = 0
    $grand = ""
    While 1
        $dossier = $repertoiresource
        
        $reject = StringLen($dossier)
        If $reject = 3 Then
            MsgBox(0, 'Rejected', "This routine is only meant for folders only. Select Again")
            $dossier_rejete = FileSelectFolder("Choose a folder this time not a drive letter.", "")
            If $dossier_rejete = "" Then Exit
            $repertoiresource = $dossier_rejete
        Else
            
            
            $Stack = $dossier & ">"; c là que ca devient intéressant ^^ =>on ajoute le symbole ">" 
        ;au nom du dossier (avec chemin)
            $FileList = $dossier & ">";idem
            While $Stack <> "";tant que "l'empilateur" (stockeur) n'est pas vide, on execute
            ;sleep(2000)
            ;on prend le nom en stock et on calcule le nombre de caractères,l'occurence cherchée étant le symbole
                $root = StringLeft($Stack, StringInStr($Stack, ">") - 1) & "\" 
            ;on prend le nom en stock et on en garde une seule partie
                $Stack = StringTrimLeft($Stack, StringInStr($Stack, ">"))
            ;maintenant on cherche le premier fichier ou dossier dans le repertoire, de n'importe quel nom
                $h = FileFindFirstFile($root & "*.*")
            ;tooltip("stack : " & $stack & " root" & $stack & " h " & $h,50,50);on affiche une barre pour mieux comprendre
                If $h > - 1 Then;si rien n'est trouvé alors
                    $FileFound = FileFindNextFile($h);on cherche le fichier suivant
                    While Not @Error And $FileFound <> "";tant qu'il n'y a pas d'erreurs et que l'on trouve quelquechose
                        If $FileFound <> "." And $FileFound <> ".." And _;on teste si on ne trouve pas de points ou autres
                                StringInStr(FileGetAttrib($root & $FileFound), "D") Then;si le fichier trouvé est un dossier
                            
                                ;___________________________
                        ;je sépare cette partie du programme car c celle là qui concerne le test de la taile du dossier
                            if round(dirgetsize($root & $filefound))/1024/1024>$max then
                        ;msgbox(0,"Attention",$root & $filefound)
                            filewriteline($fichier,"Attention, le dossier " & $filefound & "dépasse la taille")
                          endif
                        ;___________________________
                        
                          
                            
                            $Stack = $Stack & $root & $FileFound & ">";le stockeur prend le chemin du dossier trouvé (recherche recursive)
                            
                        
                          
                            $FileList = $FileList & $root & $FileFound & "<"
                            $d = $d + 1;compteur du nombre de dossiers
                            $a = $a + 1;compteur total (ici concerne seulement les dossiers
                            #cs    Else
                            
                    
                            If $FileFound = "." Or $FileFound = ".." Then
                            Else
                                $f = $f + 1;compteur du nombre de fichiers
                                $a = $a + 1;compteur total (ici concerne seulement les fichiers)
                                $FileList = $FileList & $root & $FileFound & "<"
                            EndIf
                            #ce
                        EndIf
                        
                        $len = StringLen($FileList); on teste le nombre de caractères du chemin
                        If $len > 10000 Then
                            $grand = $grand & $FileList
                            $FileList = ""
                        Else
                        EndIf
                    ;enfin on affiche le compteur
                        tooltip("Liste: Fichiers - " & $f & " Dossiers-" & $d & " Total-" & $a,500,800)
                        $FileFound = FileFindNextFile($h);et on recherche encore le suivant
                    WEnd
                    FileClose($h)
                EndIf
            WEnd
            $grand = $grand & $FileList
            $FileList = $grand
            $cleanup = StringReplace($FileList, ">", "<");nettoyage (remplacement du signe > par <)
            $outputsubdirs = StringSplit($cleanup, "<", 1)
            Return $outputsubdirs
            Exit
        EndIf
    WEnd
    FileClose($fichier)
EndFunc  ;==>_Recursive

ok it works with msgbox, but no create a file

=>i must indicate @scriptdir & "\" & "rapport.log"

i've another script that doesn't need to know the scriptdir to create a file in it, is it a bug ?

thx again man !

c u

Edited by arcker

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

Hi,

You were right to try to close the writing file "fichier" before you could open it; but pass the parameters as shown, and close it before calling notepad; then all working [or, perhaps, would work if opened and closed within func; but watch the "exit" might miss the close where you had it!]

fileclose($fichier)

if $i_DossiersSeule=0 then RunWait("Notepad.exe " & $s_RapportFichier,@ScriptDir,@SW_SHOW)

RunWait("Notepad.exe " & $s_RapportDossiers,@ScriptDir,@SW_SHOW)

Best, Randall

PS "Control-T - Tools menu/Tidy AutoIt Source - doesn't work on your lines with comments if they are "split [_ underscore] lines

Also a bug in program, I think, so comments [";"] starting without a space at the end of a line stops it (Tidy AutoIt Source) working.

Edited by randallc
Link to comment
Share on other sites

ok the project is finished ! thx you !

i try now to create a guy, and i think i'll post my program later

autoit powaaa

where can we buy autoit clothes ? just to be proud ^^

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
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...