Re: listage recursif sans les dossiers systeme

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"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

.



Relevant Pages

  • Re: listage recursif sans les dossiers systeme
    ... list the system's folder than RECYCLER etc.. ... set repParent = racine.subFolders ... output file, i.e. you must specify a drive letter and a folder name. ...
    (microsoft.public.scripting.wsh)
  • Re: Code Efficiency Suggestions
    ... > Outer loop: while not EOF of input file ... > create new output file in the new folder ... > Inner loop: while output file row counter <65000 and not input EOF ...
    (microsoft.public.excel.programming)
  • Re: Code Efficiency Suggestions
    ... Outer loop: while not EOF of input file ... create new output file in the new folder ... Inner loop: while output file row counter <65000 and not input EOF ...
    (microsoft.public.excel.programming)
  • Re: Steve, have you had any problems with C5LIB.C writing to disk?
    ... an output file for writing under MS-DOS v7.10 in real mode. ... DOSLFN, no path, full path, DOS LOCK command (to allow direct writes to ... 'short cuts' can't be copied with a 'work_space' folder to ... I use 'shortcut's for nasm and sid. ...
    (alt.lang.asm)
  • Re: How To Rebuild Objects From Text Files?
    ... new folder, but stops with the error at the line of code that I posted ... But a general Google search for "can't create the output file 2285" ... And you must have write permissions there or SaveAsText would fail. ...
    (comp.databases.ms-access)