List All Files and SubFolders Inside Folder (Any depth level
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
10 posts
Page 1 of 1
I have visual basic 2010 express edition
I google the code for this condition
& I found following code
Any 1 can solve this ??
I google the code for this condition
& I found following code
Code: Select all
But it is not working for me Dim fso
Dim ObjOutFile
'Creating File System Object
Set fso = CreateObject("Scripting.FileSystemObject")
'Create an output file
Set ObjOutFile = fso.CreateTextFile("OutputFiles.csv")
'Writing CSV headers
ObjOutFile.WriteLine("Type,File Name,File Path")
'Call the GetFile function to get all files
GetFiles("C:\Windows\Help")
'Close the output file
ObjOutFile.Close
WScript.Echo("Completed")
Function GetFiles(FolderName)
On Error Resume Next
Dim ObjFolder
Dim ObjSubFolders
Dim ObjSubFolder
Dim ObjFiles
Dim ObjFile
Set ObjFolder = fso.GetFolder(FolderName)
Set ObjFiles = ObjFolder.Files
'Write all files to output files
For Each ObjFile In ObjFiles
ObjOutFile.WriteLine("File," & ObjFile.Name & "," & ObjFile.Path)
Next
'Getting all subfolders
Set ObjSubFolders = ObjFolder.SubFolders
For Each ObjFolder In ObjSubFolders
'Writing SubFolder Name and Path
ObjOutFile.WriteLine("Folder," & ObjFolder.Name & "," & ObjFolder.Path)
'Getting all Files from subfolder
GetFiles(ObjFolder.Path)
Next
End Function
Any 1 can solve this ??
Code: Select all
You must import System.IOPublic Sub ListFolder(ByVal Parent As DirectoryInfo)
For Each SubFolder As DirectoryInfo In Parent.GetFolders()
Console.WriteLine(SubFolder.FullName) 'Write the full path of the folder to the console'
ListFolder(SubFolder) 'Loop through each folder in a recursive way'
Next
For Each File As FileInfo In Parent.GetFiles()
Console.WriteLine(File.FullName) 'Write the full path of the file to the console'
Next
End Sub
To start the function, you can for example call
Code: Select all
to list all the contents of the user (and all subfolders) folder.ListFolders(New DirectoryInfo("C:\Users"))
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Thanx for reply
but I m still confused
I created the Public Sub as u told me
But How to run that ??
but I m still confused
I created the Public Sub as u told me
But How to run that ??
I actually want something like follow
When button get click it should go to the path which is present in textbox1.text
grab all folders , files , subfolder , subfiles and store them in 1 text file (c:/temp/test1.txt)
When button get click it should go to the path which is present in textbox1.text
grab all folders , files , subfolder , subfiles and store them in 1 text file (c:/temp/test1.txt)
Code: Select all
Please tell me code in place of ListBox1.Items.Add(File)Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim directory = "E:\Torrent"
Dim files() As System.IO.FileInfo
Dim dirinfo As New System.IO.DirectoryInfo(directory)
files = dirinfo.GetFiles("*", IO.SearchOption.AllDirectories)
For Each File In files
ListBox1.Items.Add(File)
Next
End Sub
to add that file name in c:/test1.txt file
smit, please try avoiding multiple posts as it spams the topic.
Okay, try this:
Code: Select all
To run it, use this:
Public Sub ListFolder(ByVal Parent As DirectoryInfo, outputFile As StreamWriter)
For Each SubFolder As DirectoryInfo In Parent.GetDirectories()
outputFile.WriteLine(String.Format("Folder,{0},{1}", SubFolder.Name, SubFolder.Parent.FullName))
ListFolder(SubFolder, outputFile) 'Loop through each folder in a recursive way'
Next
For Each File As FileInfo In Parent.GetFiles()
outputFile.WriteLine(String.Format("File,{0},{1}", File.Name, File.Directory.FullName))
Next
End Sub
Code: Select all
Dim writer As New StreamWriter("C:\file.csv", False) 'File for writing'
writer.WriteLine("Type,File Name,File Path") 'Write CSV headers'
ListFolder(New DirectoryInfo("C:\Program Files"), writer) 'Write the contents of Program Files to C:\file.csv'
writer.Close()
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
You've posted this in the wrong section but if you don't need help anymore be sure to lock the topic
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
smashapps wrote:You've posted this in the wrong section but if you don't need help anymore be sure to lock the topicHow to lock this topic (The lock topic button is not appearing)
10 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023