futur :
DuwNext, voir aussi copie par
cpw
20220411: gaffe à l'interp^rétation des attributs, (un octet comme au temps du
MsDos ou deux actuellement):
16 bits:
https://documentation.help/MS-VBScript-fr/vsproAttributes.htm correposnd à Acer W7
bug en cours: n'inspecte pas 'system volume information' (dont le propriétaire est 'System'
soluce: ajouter le droit de lecture aux administrateurs (tests en cours)
exposé:
Il est facile de demander à Windows la taille d'un dossier (clic-droit sur son nom et propriété); mais fastidieux de le répéter pour tous ses sous-dossiers.
dans une
FenetreDeCommande,
dir /s fournit l'information sous une forme naturelle peu avenante.
la suite imite la commande
du que l'on trouve dans une fenêtre "command shell" de Linux/Unix ou "terminal" de MacOs .
Préparation:
- créez vous un "bac à sable": un dossier sur le disque ou une clé Usb
- ouvrez une Fenêtre de commande COMME ADMINISTRATEUR
- placez vous dans le bac à sable par la commande cd
- SOON si votre antivirus le permet, téléchargez le fichier
- sinon
- créer un fichier texte nommé duw.vbs par la commande: notepad duw.vbs
- y copier les lignes du cadre ci dessous
- pour une installation pérenne, voir InstallWindowsLookAnsFeelApp (fait sur AcerM1641W7)
Appel dans une FenetreDeCommande:
cscript [chemin_d'accès\]duw.vbs [options] chemin_du_disque_ou_répertoire_à_explorer
pour diriger la liste dans un fichier: utilisez l'option -O,
voire (si aucun caractère unicode) cscript duw.vbs X: > resu.txt
les options sont:
taille de
cluster (à découvrir par la commande
chkdsk)
- -C xxxxx: compter l'espace utilisé selon la taille des cluster
- -B: préparer un fichiuer de commande (.bat)
- -D: afficher la date et heure de création
- -M: afficher la date et heure de modification
- -O <file name> ; diriger le résutat vers le fichier
- -i diverses information sur le disque.
- -f ne pas lister les fichiers
- -r ne pas lister les dossiers
- --help, -?: aide (plus que sommaire!)
Appel en mode graphique:
- lancement au choix:
- 2xclic(ou clic-droit ouvrir) sur l'icône duw.vbs et entrer le disque/chemin à explorer
- "draguer" le disque ou le dossier sur l'icone "duw.vbs"
- entrer le nom du fichier cible qui contiendra le résultat (gaffe au chemin implicite)
promotion de noël (à livrer le 25 décembre)
- options
- nos pour ignorer les fichiers "système"
- noh ignorer les fichiers/répertoires cachés
- bat crée un .bat de mkdir et copy
- attributs ecrits précédé de :
Code (VbScript) pour duw.vbs
option explicit
'msgbox isAdmin(), vbOkonly, "Am I an admin?"
' 2do: wscript and prameters
' executed by wscript or cscript ?
' au choix
' supprimer option -q
' previr un "error only"
dim APO 'pour emballer les noms de fichier/dossiers
APO="'"
dim erroronly
erroronly=false
dim seeowner
seeowner=false
dim REMARK
REMARK = ""
dim CALLR
CALLR=""
dim CALLF
CALLF="F"
dim UNPRINTABLE
UNPRINTABLE = "Unicode character "
dim CONSEIL
CONSEIL="Try again with option -o <file> " & vbcrlf & "'Ok' to continue" & vbcrlf & "'Annuler' to quit."
dim papa ' pour dire dans quel directory on fouine
papa=""
dim who, w
who= ucase(wscript.fullname)
if instr(who,"CSCRIPT")>0 then
w=false
elseif instr(who,"WSCRIPT")>0 then
w=true
else
wscript.echo "unknown handler "& who
wscript.quit
end if
dim version
version="http://antiguide.free.fr/wiki/wakka.php?wiki=duw, 20250402-20:00 "
dim fs
set fs=createobject("scripting.filesystemobject")
dim gui
dim count
count=wscript.arguments.count
dim stdout
dim done
done=false ' sera true si option -o <fichier>
if w then
gui=true
' trop tot pour ouvrir fichier resultats on connait pas encore son nom!
else
gui=false
' Set stdout = fs.GetStandardStream (1)
dim candidat
candidat=""
' if true then ' bof en trop!
' si paramètre -O trouvé, chercher valeur
dim ipar
for ipar=0 to count-2
dim opt1
opt1=ucase(wscript.arguments.item(ipar))
if opt1="-O" then
candidat=wscript.arguments.item(ipar+1)
' msgbox "param -O "& candidat
' gaffe accepte deux -O! le premier ignoré 20250330
end if
next 'ipar
if candidat<>"" then
Set stdout = fs.createtextfile(candidat,,true)
done=true
' msgbox "created"
else '
Set stdout = fs.GetStandardStream (1)
''msgbox "stdout created"
dim stderr
Set stderr = fs.GetStandardStream (2)
end if ' not done
end if
'msgbox "stdout not gui open "
'Set stdout = fs.GetStandardStream (1)
'msgbox "stdout created"
' po end if ' W gui
' wscript.quit
dim quiet
quiet=false
dim stampd
stampd=false
dim stampm
stampm=false
dim stampu
stampu=false
dim showattr
showattr=false
dim nberr
nberr=0
dim nbfiles
dim nbfolders
nbfolders=0
nbfiles=0
dim listfiles
listfiles=true
dim listfolders
listfolders=true
dim exploresub
exploresub=true
dim bsize
bsize=1
dim trailer
trailer="\"
dim lev
if w then
if count=1 then
lev=wscript.arguments(0)
msgbox lev
else
lev=inputbox ("duw " &vbcrlf & _
version & vbcrlf & _
"entrez le chemin à explorer" & vbcrlf & _
"ici exécution gui " & vbcrlf & _
"pour exécuter dans une fenetre de commande " & vbcrlf & _
"annuler et entrer la commande: cscript duw.vbs" )
' faudtari tester button
if len(lev)=0 then
' msgbox "Oooops"
wscript.quit
end if
end if ' lev
dim out
dim where
where=fs.GetAbsolutePathName(".")
out=inputbox ( "duw " &vbcrlf &_
version & vbcrlf & _
"Entrez le nom du fichier destinataire de la liste" & vbcrlf & _
"in: " & where &"\.")
if len(out)=0 then
msgbox "no out file"
wscript.quit
end if
out=fs.GetAbsolutePathName(".") &"\"&out
set stdout=fs.createtextfile(out)
' msgbox "ok creation " & out
stdout.writeline "duw ("&version&")"
stdout.writeline "Started @ "&now
else ' donc c pas windows
stdout.writeline "duw ("&version &")"
stdout.writeline "Started @ "&now
dim ic
for ic=0 to count-1
dim opt
opt=ucase(wscript.arguments.item(ic))
stdout.write REMARK&"param: "& opt
if ucase(opt)="-O" then stdout.write " " & wscript.arguments.item(ic+1)
stdout.writeline
select case mid(opt,1,2)
case "-P" : seeowner=true
case "-O": ic=ic+1 ' ignore next parametre , see later
case "-I":
info( wscript.arguments.item(count-1))
wscript.quit
' case "-Q": quiet=true
' case "-C": bsize=mid(opt,3) 'format -Cxxxx , no space
' stdout.writeline REMARK&"Cluster-size set to " & bsize
case "-C": ic=ic+1
bsize=wscript.arguments.item(ic)
stdout.writeline REMARK&"Cluster-size set to " & bsize
case "-B":
CALLF="call f.bat"
CALLR="call r.bat"
' faéire callx
REMARK="REM "
case "-D": stampd=true
case "-M": stampm=true
case "-U": stampu=true
case "-A": showattr=true
case "-E": erroronly=true
case "-F": listfiles=false
case "-R": listfolders=false
case "-S": exploresub=false
case "--HELP" : dohelp
case "-?" : dohelp
wscript.quit
case else:
if ic<count-1 then
stdout.writeline REMARK&"unknown!"
wscript.quit
end if
end select
next 'ic
' si aucun paramet comme --help
if count=0 and not w then
dohelp
wscript.quit
end if
if not w then
dim nlev
nlev=wscript.arguments.item(count-1)
end if
end if
dim objshell
Set objShell = WScript.CreateObject("WScript.Shell")
stdout.writeline "userprofile " & objShell.Environment("PROCESS").Item("USERPROFILE")
stdout.writeline "username: " & objShell.Environment("PROCESS").Item("USERNAME")
stdout.writeline "admin: "&isadmin()
stdout.writeline REMARK&"folder 2 scan: "&nlev
lev= fs.getabsolutepathname(nlev)
level(lev)
if nberr>0 then stdout.writeline "#errors: "&nberr
stdout.writeline REMARK&"#folders: "&nbfolders
stdout.writeline REMARK&"#files: "&nbfiles
' if not gui then stderr.writeline "Ended @ "&now
stdout.writeline REMARK&"Ended @ "&now
' POURRAIT AJOUTER ERREURS
function level(precu)
' stdout.writeline "on entre dans level ("&precu&")"
dim big
big=0
dim pclean
dim p
pclean=precu
p=precu
dim s,smax
s=0 ' taile en byte
smax=0 'taille arrondie au cluster supérieur
on error resume next
dim fo
set fo=fs.getfolder(p)
if err.number>0 then
stdout.writeline "erreur "&err.number&" " & err.description & " en lecture dossier: " & p
stdout.writeline "ABANDON (1)"
' msgbox "erreur "&err.number & " en lecture dossier: " & p & vbcrlf & "ABANDON"
err.clear
on error goto 0
level=-1
exit function
end if
on error goto 0
' stdout.writeline "ok getfolder"
if listfolders then
dim xxx
' pas de date sur la racine
if len(p)>3 or mid(p,2,2)<>":\" then
on error resume next
xxx=stamp(fo)
if err.number>0 then
msgbox err.description & vbcrlf & err.line
on error goto 0
end if
else
on error goto 0
end if
on error resume next
if listfiles then
' si listfile, ob annonce le repertroier en ecploration
if not erroronly then stdout.writeline CALLR & "X " & prop(p) & " " & att(fo) & xxx & APO & p & APO
end if
dim mema
mema=att(fo)
if err.number>0 then
'msgbox err.description
err.clear
pclean=cleaned(p)
if not quiet then
if 2=msgbox (UNPRINTABLE & " in folder: "&vbcrlf & papa & vbcrlf & "subfolder:"&vbcrlf&"<"&p &">"& vbcrlf & " overstamped: " & vbcrlf & pclean & vbcrlf & CONSEIL, vbokcancel ) _
then wscript.quit
end if
on error goto 0
stdout.writeline REMARK & "NAME FOLDER ERROR, INVALID (UNICODE?) CHARACTERS OVERSTAMPED WITH '?' in list ."
end if
on error goto 0
end if 'list folder
dim fc, onefile, fsize, fmax, ffixe
' owner in progress
' sans doute JAMAIS on est dans le dossier aurait été rejetté au niveau au dessus
if (fo.attributes and 1024)=1024 then
stdout.writeline REMARK & "LIEN DOSSIER IGNORE: " & fo.name & " " & fo.attributes& " " & att(fo.attributes)
else
Set fc = fo.Files
'protection et si erreur on va apres next
on error resume next
For Each onefile in fc
if err.number>0 then
stdout.writeline REMARK & "in folder '"& p & "' GET FILE ERROR, file(s) in folder ignored"
err.clear
exit function
else
on error goto 0
'stdout.writeline "ok each onefile"
if (onefile.attributes and 1024)=1024 then
if not erroronly then stdout.writeline callr & "L " & att(onefile) & xxx & APO & p & onefile.name & APO
else
nbfiles=nbfiles+1
fsize=onefile.size
big=big+fsize
fmax=bsize*int((fsize+bsize-1)/bsize)
ffixe=fixe(fmax)
'stdout.writeline fsize & " " & bsize & " " &fmax & " " & ffixe
dim n
n=onefile.name
dim tout
dim pplus
pplus="\"
if mid(p,len(p),1)="\" then pplus=""
'msgbox "'" & pclean & pplus & n & "'"
tout= CALLF & ffixe &" "&prop(pclean & pplus & n ) & " " & att(onefile) & stamp(onefile) & APO & pclean & pplus & n & APO
if listfiles then
on error resume next
if not erroronly then stdout.writeline tout
if err.number>0 then
dim nclean
nclean=cleaned(n)
if not quiet then
if 2=msgbox (UNPRINTABLE &" in folder:" & vbcrlf & pclean & vbcrlf & "file name: "&vbcrlf & n & vbcrlf & " overstamped in list: (play again without -q for show originel name)." & vbcrlf & nclean & vbcrlf & CONSEIL,vbokcancel) _
then wscript.quit
end if
err.clear
on error goto 0
msgbox "'" & pclean & pplus & n & "'"
tout= CALLF & ffixe &" "&prop(pclean & pplus & n) & " " & att(onefile) & stamped(onefile) & APO & pclean & pplus & nclean & APO
stdout.writeline erroronly
if not erroronly then stdout.writeline tout
end if
on error goto 0
end if
end if ' du on error qui encadre for
end if 'file attr <>1024
Next ' fc files 1
' stdout.writeline REM & "files:"&big
' ------------------- now explore folders
Set fc = fo.subFolders
dim onefolder
For Each onefolder in fc
nbfolders=nbfolders+1
dim f2, anti, p2
on error resume next
' 20250401
set f2=fs.getfolder(onefolder)
if err.number>0 then
stdout.writeline "erreur "&err.number&" " & err.description & " en lecture dossier: " & p
stdout.writeline "ABANDON (2)"
' msgbox "erreur "&err.number & " en lecture dossier: " & p & vbcrlf & "ABANDON"
exit function
end if
err.clear
on error goto 0
' filtre links
' stdout.writeline "lien ? " & onefolder.name & " " & onefolder.attributes
if (onefolder.attributes and 1024)=1024then
' 20250401 pourrait formater normalement
if not erroronly then stdout.writeline callr & "L "& prop(onefolder.name) & " " & att(onefolder) & xxx & APO & p & onefolder.name & APO
else
p2=f2.name
anti=""
if mid(p,len(p))<>"\" then anti="\"
papa=p
' stdout.writeline "on traite " & p &anti & p2
if not exploresub and not erroronly then stdout.writeline CALLR & "I " & att(fo) & xxx & APO & p & anti& p2 & APO
if exploresub then fsize=level(p & anti& p2)
'stdout.writeline REM & "taille du sous folder: "&p& anti& p2&" " &fsize
big=big +fsize
'stdout.writeline REM & "tail en progres de " & precu&" " & big
fmax=bsize*int((fsize+bsize-1)/bsize)
smax=smax+fmax
end if ' attr 1024 f
Next ' fc folders
end if ' attr
dim t1
t1=trailer
if mid(p,len(p))="\" then t1=""
' INCERTAIN ?
' if listfiles then stdout.writeline "?????"&fixe(smax) &" "&att & pclean & t1
level=big
' stdout.writeline REMARK & fixe(big) & " "&APO&pclean&APO
if not erroronly then stdout.writeline "R" & fixe(big) & " " & prop(pclean) & " " & mema & APO&pclean&APO
end function
function fixe(n)
dim nn
dim f
nn=n
f=" " & nn
fixe=mid(f,len(f)-14,3)+" "+mid(f,len(f)-11,3)+" "++mid(f,len(f)-8,3)+" "+mid(f,len(f)-5,3)+" "+mid(f,len(f)-2,3)
end function
sub info (ll)
dim l
l=ll
if len(l)=1 then l=l&":"
dim objdrive
on error resume next
Set objdrive = fs.GetDrive(fs.GetDriveName(l))
if err.number>0 then
on error goto 0
stdout.writeline "ERROR ACCESSING DRIVE: " & l
wscript.quit
else
on error goto 0
end if
stdout.writeline "Available space: " & objDrive.AvailableSpace
stdout.writeline "Drive letter: " & objDrive.DriveLetter
stdout.writeline "Drive type: " & objDrive.DriveType
stdout.writeline "File system: " & objDrive.FileSystem
stdout.writeline "Free space: " & objDrive.FreeSpace
stdout.writeline "Is ready: " & objDrive.IsReady
stdout.writeline "Path: " & objDrive.Path
stdout.writeline "Root folder: " & objDrive.RootFolder
stdout.writeline "Serial number: " & objDrive.SerialNumber
stdout.writeline "Share name: " & objDrive.ShareName
stdout.writeline "Total size: " & objDrive.TotalSize
stdout.writeline "Volume name: " & objDrive.VolumeName
end sub
function att(n)
' stdout.writeline "att name " & n.name& " " & n.attributes
if showattr then
dim lettre
lettre="RHSVDA....LC"
dim a
a=""
dim nn
on error resume next
nn=n.attributes
if err.number > 0 then
' stdout.writeline "appel vide"
att="?????????"
exit function
end if
on error goto 0
dim i
for i=1 to 12
if (i<7) or (i>10) then
dim u
' stdout.writeline "nn " & nn
u= nn and 1
if u=1 then
a=a&mid(lettre,i,1)
else
a=a&"."
end if
end if
nn=int(nn /2)
next 'i
att=APO&a&APO&" "
else
att=" "
end if
end function
function cleaned(p)
dim ret
ret=""
dim iclear
for iclear = 1 to len(p)
dim unaclear
unaclear=mid(p,iclear,1)
if unaclear>chr(127) or unaclear<chr(32) then unaclear="?"
ret=ret & unaclear
next
cleaned=ret
end function
function stamp(x)
dim w
dim pod
dim pou
dim pom
pod=""
pom=""
pou=""
if stampd then
w= x.datecreated
pod=APO & mid(w,7,4)& mid(w,4,2)& mid(w,1,2)& mid(w,11)&APO& " "
end if
if stampu then
w= x.datelastaccessed
pou=APO & mid(w,7,4)& mid(w,4,2)& mid(w,1,2)& mid(w,11)&APO& " "
end if
if stampm then
w= x.datelastmodified
pom=APO & mid(w,7,4)& mid(w,4,2)& mid(w,1,2)& mid(w,11)&APO& " "
end if
stamp=pod & pom & pou
end function
sub dohelp
stdout.writeline " Usage: cscript [path]duw.vbs [options] <folder to scan>"
stdout.writeline " Options:"
stdout.writeline " -o <file name> : list file"
stdout.writeline " -b prepare bat file"
stdout.writeline " -i information about disk drive"
stdout.writeline " (but not the cluster size: use chkdsk) "
stdout.writeline " -f don't list files "
stdout.writeline " -r don't list directories "
stdout.writeline " -s don't explore sub-directories "
stdout.writeline " -c xxxxxx display space used if clusters xxxxxx"
stdout.writeline " needed to display the space USED on disk"
stdout.writeline " use chkdsk to know cluster-size"
' stdout.writeline " -q quiet replace unprintable characters"
stdout.writeline " -d print date & time creation"
stdout.writeline " -m print date & time modification"
'stdout.writeline " -u print date & time last used"
stdout.writeline " -a print attributes"
stdout.writeline " -p print owner"
stdout.writeline " -e print error only"
end sub
Private Function IsAdmin()
On Error Resume Next
CreateObject("WScript.Shell").RegRead("HKEY_USERS\S-1-5-19\Environment\TEMP")
if Err.number = 0 Then
IsAdmin = True
else
IsAdmin = False
end if
Err.Clear
On Error goto 0
End Function
function prop(strfilename)
if not seeowner then
prop=""
exit function
end if
dim objWMIService
Set objWMIService = GetObject("winmgmts:")
'exit function
'msgbox strfilename
'strFileName = t
'stdout.writeline "owner " & strFileName
dim objFileSecuritySettings
on error resume next
Set objFileSecuritySettings = _
objWMIService.Get("Win32_LogicalFileSecuritySetting='" & strFileName & "'")
if err.number >0 then
prop="---"
exit function
end if
on error goto 0
dim intretval
dim objSD
on error resume next
intRetVal = objFileSecuritySettings.GetSecurityDescriptor(objSD)
if err.number >0 then
prop="---"
exit function
end if
on error goto 0
If intRetVal = 0 Then
on error resume next
prop= objsd.Owner.Domain & "\" & objSD.Owner.Name
if err.number >0 then
prop="!!!"
exit function
end if
on error goto 0
Else
prop="???"
End If
end function