HELL
23-05-2005, 11:41
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 :doh: ).
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
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