|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Dec 2000
Città: Finale Emilia (MO)
Messaggi: 282
|
[vbscript] Lista cartelle e sottocartelle
Ho il seguente problema...vorrei poter creare un file contenente una lista di cartelle e sotto cartelle del mio disco.Per ora sono riuscito solo a scendere di 2 livelli ossia vedo le cartelle e le sotto cartelle ma, vorrei vedere pure le sottocartelle delle sottocartelle (detta così fa un po pena lo so
).Visto che ho iniziato da pochi giorni a smanettare con vb non uccidetemi se sto script è un casino : Option Explicit Dim NomeFile, NomeInserito, Estensione, ListaCartelle, CartellaPrincipale, Cartella CartellaPrincipale = "c:\" Estensione = ".txt" NomeInserito = InputBox("Inserisci un nome file") NomeFile = NomeInserito&Estensione ListaCartelle = MostraListaCartelle(CartellaPrincipale) Call TextStreamTest Function TextStreamTest Const Lettura = 1, Scrittura = 2, Aggiunta = 8 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 Dim oFSO, oFILE, oTS Set oFSO = CreateObject("Scripting.FileSystemObject") oFSO.CreateTextFile(NomeFile) ' Create a file. Set oFILE = oFSO.GetFile(NomeFile) Set oTS = oFILE.OpenAsTextStream(Scrittura, TristateUseDefault) oTS.Write(ListaCartelle) oTS.Close End Function Function MostraListaCartelle(folderspec) Dim oFSO, oF, f1, oS, oSF Set oFSO = CreateObject("Scripting.FileSystemObject") Set oF = oFSO.GetFolder(folderspec) Set oSF = oF.SubFolders For Each f1 In oSF oS = oS & f1.name & VbCrLf oS = oS & MostraListaSottoCartelle(CartellaPrincipale&f1.name) Next MostraListaCartelle = oS End Function Function MostraListaSottoCartelle(folderspec) Dim oFSO, oF, f2, oS, oSF Set oFSO = CreateObject("Scripting.FileSystemObject") Set oF = oFSO.GetFolder(folderspec) Set oSF = oF.SubFolders For Each f2 In oSF oS = oS & " " & f2.name oS = oS & VbCrLf Next MostraListaSottoCartelle = oS End Function So che potrei farmi un tree da dos su un file ma mi servirebbe farlo in vb Grazie in anticipo
__________________
AMD Associazione Menti Deviate |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Dec 2000
Città: Finale Emilia (MO)
Messaggi: 282
|
Sono riuscito a risolvere il problema usando il comando path :
Option Explicit Dim NomeFile, NomeInserito, Estensione, ListaCartelle, CartellaPrincipale, Cartella CartellaPrincipale = "c:\" Estensione = ".txt" NomeInserito = InputBox("Inserisci un nome file") NomeFile = NomeInserito&Estensione ListaCartelle = MostraListaCartelle(CartellaPrincipale) Call TextStreamTest Function TextStreamTest Const Lettura = 1, Scrittura = 2, Aggiunta = 8 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 Dim oFSO, oFILE, oTS Set oFSO = CreateObject("Scripting.FileSystemObject") oFSO.CreateTextFile(NomeFile) ' Create a file. Set oFILE = oFSO.GetFile(NomeFile) Set oTS = oFILE.OpenAsTextStream(Scrittura, TristateUseDefault) oTS.Write(ListaCartelle) oTS.Close End Function Function MostraListaCartelle(folderspec) Dim oFSO, oF, f1, oS, oSF, oP Set oFSO = CreateObject("Scripting.FileSystemObject") Set oF = oFSO.GetFolder(folderspec) Set oSF = oF.SubFolders oP = oF.Path For Each f1 In oSF oS = oS & f1.name & VbCrLf oS = oS & MostraListaSottoCartelle(oP&f1.name) Next MostraListaCartelle = oS End Function Function MostraListaSottoCartelle(folderspec) Dim oFSO, oF, f2, oS, oSF, oP Set oFSO = CreateObject("Scripting.FileSystemObject") Set oF = oFSO.GetFolder(folderspec) Set oSF = oF.SubFolders oP = oF.Path For Each f2 In oSF oS = oS & " " & f2.name & VbCrLf oS = oS & MostraListaSottoCartelle2(oP& "\" & f2.name) Next MostraListaSottoCartelle = oS End Function Function MostraListaSottoCartelle2(folderspec) Dim oFSO, oF, f3, oS, oSF, oP Set oFSO = CreateObject("Scripting.FileSystemObject") Set oF = oFSO.GetFolder(folderspec) Set oSF = oF.SubFolders oP = oF.Path For Each f3 In oSF oS = oS & " " & f3.name & VbCrLf oS = oS & MostraListaSottoCartelle(oP& "\" & f3.name) Next MostraListaSottoCartelle2 = oS End Function Solo che ora devo riuscire ad impaginarle come si deve visto che viene na roba simile Codice:
i386 ASMS 1 DEFAULT
__________________
AMD Associazione Menti Deviate |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Dec 2000
Città: Finale Emilia (MO)
Messaggi: 282
|
Bello mi fo un monologo
Per ovviare al problema degli spazi ho deciso di fargli stampare la path + il \ necessario. In ogni caso se qualcuno sa come fare per gli spazi sarebbe meglio visto che stampando il path l'operazione risulta appesantita
__________________
AMD Associazione Menti Deviate |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 13:10.










).








