Re: listage recursif sans les dossiers systeme
- From: "Pegasus \(MVP\)" <I.can@xxxxxxxxxx>
- Date: Mon, 23 Feb 2009 17:03:29 +0100
"karamel" <karamel@xxxxxxxx> wrote in message
news:49a2c088$0$12648$ba4acef3@xxxxxxxxxxxxxxxxx
Hello,
j want list my disque in a fichier, but i have in the liste the system's
folder (RECYCLER etc...)
i don't want.
j have test many scrypt but it's not good
help me please
thank you
________________________________________________
maRacine="g:\"
Set fso = CreateObject("Scripting.FileSystemObject")
afficherArborescence(fso.getFolder(maRacine))
wscript.quit
function afficherArborescence(racine)
set repParent = racine.subFolders
for each repEnfant in repParent
Set fso_repEnfant = fso.GetFolder(repEnfant)
On Error Resume Next
Set fso_listing = fso.OpenTextFile("listing.txt", 8, true)
fso_listing.writeline("------------------------------------------------------------------------------------")
fso_listing.close
For each fichier in fso.GetFolder(repEnfant).Files
Set fso_listing = fso.OpenTextFile("listing.txt", 8, true)
fso_listing.writeline(repEnfant & "\" & fichier.Name & " -- " &
fichier.size)
fso_listing.close
next
afficherArborescence(repEnfant)
next
end function
Your basic idea is fine but there are a few minor problems:
- It is wasteful to open and close the output file all the time. You should
open it once in the main routine and close it also in the main routine.
- You should open the output file as "write", not as "append".
- If want a robust program then you MUST provide a full path to your output
file, i.e. you must specify a drive letter and a folder name.
- You should only write to the output file when you can access the current
folder. Check err.number to see if there is a problem opening it.
- You could simplify [fso_listing.writeline(repEnfant & "\" & fichier.Name
&] to [fso_listing.writeline(fichier.path &]
Here is your modified code:
maRacine="g:\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fso_listing = fso.OpenTextFile("c:\listing.txt", 2, True)
afficherArborescence(fso.getFolder(maRacine))
fso_listing.close
WScript.quit
Function afficherArborescence(racine)
Set repParent = racine.subFolders
For Each repEnfant In repParent
Set fso_repEnfant = fso.GetFolder(repEnfant)
fso_listing.writeline("------------------------------------------------------------------------------------") On Error Resume Next For Each fichier In fso.GetFolder(repEnfant).Files If Err.number = 0 then _ fso_listing.writeline(fichier.path & " -- " & fichier.size) Next afficherArborescence(repEnfant) NextEnd Function
.
- Follow-Ups:
- Re: listage recursif sans les dossiers systeme
- From: karamel
- Re: listage recursif sans les dossiers systeme
- References:
- listage recusif sans les dossiers systeme
- From: karamel
- listage recusif sans les dossiers systeme
- Prev by Date: listage recusif sans les dossiers systeme
- Next by Date: Re: listage recursif sans les dossiers systeme
- Previous by thread: listage recusif sans les dossiers systeme
- Next by thread: Re: listage recursif sans les dossiers systeme
- Index(es):
Relevant Pages
|