I want to get data from folder and multiple subfolder. How to solve?
My folder design
---------------------------
Main folder
Folder 1
Folder 2
Folder 3
Folder 4
In this condition, I only got folder 1 , 2 and 4.I cannot get folder 3.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Saber ShaikhPosted Apr 15, 2015, 2:28 AM
public string[] GetSubFolder(string path)
{
List
string[] _CurrentDirectoryList = System.IO.Directory.GetDirectories(path);
_subdirectoryList.AddRange(_CurrentDirectoryList);
foreach (string _directorypath in _CurrentDirectoryList)
{
_subdirectoryList.AddRange(GetSubFolder(_directorypath));
}
return _subdirectoryList.ToArray();
}
My Blog
Manoj BhoirPosted Apr 14, 2015, 6:04 AM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
List
string[] _directoryList;
_directoryList = System.IO.Directory.GetDirectories("Your Directory Path");
_finaldirectoryList.AddRange(_directoryList);
foreach (string _directorypath in _directoryList)
{
_finaldirectoryList.AddRange(GetSubFolder(_directorypath));
}
//_directoryList contains all subfolder paths
}
public string[] GetSubFolder(string path)
{
List
string[] _CurrentDirectoryList = System.IO.Directory.GetDirectories(path);
_subdirectoryList.AddRange(_CurrentDirectoryList);
foreach (string _directorypath in _CurrentDirectoryList)
{
_subdirectoryList.AddRange(GetSubFolder(_directorypath));
}
return _subdirectoryList.ToArray();
}
}
}
You can use substring to extract folder name from list of paths.
I hope this will help you. :)
Khargesh RajputPosted Apr 14, 2015, 4:11 AM
path="mainfolder/folder2/folder3/";
or
http://www.c-sharpcorner.com/code/616/get-list-of-directory-folder-with-path-in-project.aspx
Asp.Net HeinPosted Apr 14, 2015, 4:09 AM
Ankur JainPosted Apr 14, 2015, 4:08 AM
try like this..
Khargesh RajputPosted Apr 14, 2015, 4:07 AM