C# .NET - retrive folders name
Asked By hiren dhameliya on 21-Mar-12 06:39 AM
Hi,
i want to retrive folders name from one directoriy .....how i retrive all folder name for one perticular folder ......
and files as well
#reply me as soon as possbile..
thanks...
D Company replied to hiren dhameliya on 21-Mar-12 07:47 AM
Hello,
U can use getfilename method to fetch the folder name , like this
string folderName = Path.GetFileName( Path.GetDirectoryName( "Here your path ") ); if u want to fetch all file in specific drive then do like this
string[] filearray= Directory.GetFiles(@"Your Drive ", "*.BIN");
follow this MSDN article for more detail
http://msdn.microsoft.com/en-us/library/6yk7a1b0.aspx
Regards
D

Zip (unzip) & asp.net .NET Framework
component for zipping and unzipping files using c# in ASP.net? Thnx ASP.NET Discussions Path.GetFileName (1) DotNetZip.Works (1) Directory.CreateDirectory (1) Directory.GetDirectories (1) Response.OutputStream (1) Directory.GetFiles (1) File.OpenRead (1) GetFileName (1) A google search for Asp.Net zip unzip got theEntry; string tmpEntry = String.Empty; while ((theEntry = s.GetNextEntry()) ! = null) { string directoryName = outputFolder; string fileName = Path.GetFileName(theEntry.Name); / / create directory if (directoryName ! = "") { Directory.CreateDirectory(directoryName); } if (fileName ! = String.Empty) { if (theEntry Name.IndexOf(".ini") < 0) { string fullPath = directoryName + " \ " + theEntry.Name; fullPath = fullPath.Replace(" \ ", " \ "); string fullDirPath = Path.GetDirectoryName(fullPath); if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath); FileStream streamWriter = File.Create(fullPath); int size
if (eventArgs.CommandLine.Count > 0) { foreach (string s in eventArgs.CommandLine) { foreach (string ThisFileName in Directory.GetFiles(Path.GetDirectoryName(s), Path.GetFileName(s), SearchOption.TopDirectoryOnly)) { ((ManagerMDI)this.MainForm).OpenFile(ThisFileName); } } } } void SingleInstanceApplication_Startup(object sender, StartupEventArgs eventArgs) { if eventArgs.CommandLine.Count > 0) { foreach (string s in eventArgs.CommandLine) { foreach (string ThisFileName in Directory.GetFiles(Path.GetDirectoryName(s), Path.GetFileName(s), SearchOption.TopDirectoryOnly)) { ((ManagerMDI)this.MainForm).OpenFile(ThisFileName); } } } } } static class
Process cannot access the file, it is already in use by another process Mobile Apps
I am using simple File Delete method. could any one please tell me. string[] files = Directory.GetFiles(zipsPath); foreach (string file in files) { try { if (File.Exists(file)){ File.Delete(file); } } catch Could not be deleted :" + ex.Message); } } Thanks, Aruna.G PocketPC Developer Discussions Path.DirectorySeparatorChar (1) Path.GetDirectoryName (1) Path.GetFileName (1) Directory.CreateDirectory (1) Directory.GetFiles (1) File.OpenRead (1) Directory.Exists (1) Directory.Delete (1) The file is still open
me solution. You can use the Directory class for that: using "System.IO" ; . . . string [] files = Directory.GetFiles( "path" ); Replace "path" with the directory to search for the files in. There is also then if u just want to get the filename then i think u can use Path.GetFileName Method The following tip will help you to dig out the following details from Full Imports System.IO Dim _FullPath As String = " C: \ Users \ Sony \ Desktop \ Readme.txt" <br> MsgBox(Path.GetFileName(_FullPath)) ' Returns > > Readme.txt MsgBox(Path.GetExtension(_FullPath)) ' Returns > > .txt MsgBox(Path.GetFileNameWithoutExtension(_FullPath)) ' Returns > > Readme MsgBox(Path.GetDirectoryName(_FullPath)) ' Returns > > C: \ Users \ Sony \ Desktop MsgBox(Path.GetPathRoot(_FullPath)) ' Returns > > C: \ < / br> thanku so
As String = System.IO.Path.GetExtension(tDirToZip) If (tExt <> String.Empty) Then tDirToZip = System.IO.Path.GetDirectoryName(tDirToZip) ElseIf (tDirToZip.EndsWith(" \ ")) Then tDirToZip = tDirToZip.Substring(0, tDirToZip.Length - 1) End If 'If If (qFileNameOut = Nothing) Then qFileNameOut = String.Empty End If Dim tOutputDir As String = System.IO.Path.GetDirectoryName(qFileNameOut) If (tOutputDir = String.Empty) Then If (qFileNameOut = String.Empty) Then qFileNameOut = "backup.zip" End Each tDir In tDirs ZipDir(s, crc, tDir, qStartDir, tOutputName) Next Dim filenames() As String = Directory.GetFiles(qDirName) Dim file1 As String continue: For Each file1 In filenames If qStartDir.ToUpper() = qDirName.ToUpper() Then If (file1.ToUpper().EndsWith(System.IO.Path.GetFileName(tOutputName))) Then 'Skip this one. . . GoTo continue End If End If Dim tOpened As Boolean
As String = System.IO.Path.GetExtension(tDirToZip) If (tExt <> String.Empty) Then tDirToZip = System.IO.Path.GetDirectoryName(tDirToZip) ElseIf (tDirToZip.EndsWith(" \ ")) Then tDirToZip = tDirToZip.Substring(0, tDirToZip.Length - 1) End If 'If If (qFileNameOut = Nothing) Then qFileNameOut = String.Empty End If Dim tOutputDir As String = System.IO.Path.GetDirectoryName(qFileNameOut) If (tOutputDir = String.Empty) Then If (qFileNameOut = String.Empty) Then qFileNameOut = "backup.zip" End Each tDir In tDirs ZipDir(s, crc, tDir, qStartDir, tOutputName) Next Dim filenames() As String = Directory.GetFiles(qDirName) Dim file1 As String continue: For Each file1 In filenames If qStartDir.ToUpper() = qDirName.ToUpper() Then If (file1.ToUpper().EndsWith(System.IO.Path.GetFileName(tOutputName))) Then 'Skip this one. . . GoTo continue End If End If Dim tOpened As Boolean
ArrayList GenerateFileList(string Dir) { ArrayList fils = new ArrayList(); bool Empty = true; foreach (string file in Directory.GetFiles(Dir)) / / add each file in directory { fils.Add(file); Empty = false; } if (Empty) { if (Directory theEntry; string tmpEntry = String.Empty; while ((theEntry = s.GetNextEntry()) ! = null) { string directoryName = outputFolder; string fileName = Path.GetFileName(theEntry.Name); / / create directory if (directoryName ! = " ") { Directory.CreateDirectory(directoryName); } if (fileName ! = String.Empty) { if (theEntry Name.IndexOf(" .ini ") < 0) { string fullPath = directoryName + " \ " + theEntry.Name; fullPath = fullPath.Replace(" \ ", " \ "); string fullDirPath = Path.GetDirectoryName(fullPath); if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath); FileStream streamWriter = File.Create(fullPath); int size ArrayList GenerateFileList(string Dir) { ArrayList fils = new ArrayList(); bool Empty = true; foreach (string file in Directory.GetFiles(Dir)) / / add each file in directory { fils.Add(file); Empty = false; } if (Empty) { if (Directory
are not supported." I'm using C#, with .NET CF 3.5. Code: string strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); string [] files = Directory.GetFiles(strAppDir, "*.xml" ); / / <- Designer indicates error is here. G ranted the path contained within strAppDir does get just the full filename, I'd use: Uri uri = new Uri ( hreflink ); string filename = Path . GetFileName ( uri . LocalPath ); refer the links http: / / stackoverflow.com / questions / 1105593 / get-file-name-from-uri one of two solutions: 1) How to stop the VS2008 Designer from complaining about the Directory.GetFiles method, or 2) use some other method that will provide me with an array of
in Directory .GetDirectories(textBox1.Text)) { ctrlid = id_nam.Substring(id_nam.LastIndexOf( " \ " ) + 1); foreach ( string zip_nam in Directory .GetFiles(id_nam)) { if (zip_nam.EndsWith( ".zip" )) { Jobnam = zip_nam.Substring(0, zip_nam.LastIndexOf( "." )); Jobnam = Jobnam.Substring(Jobnam OpenRead(zip_nam)); ZipEntry theEntry; tmpEntry = String .Empty; while ((theEntry = s.GetNextEntry()) ! = null ) { directoryName = id_nam; fileName = Path .GetFileName(theEntry.Name); / / create directory if ( Directory .Exists(directoryName)) { Directory .CreateDirectory(directoryName); } if (fileName ! = String .Empty if (theEntry.Name.IndexOf( ".ini" ) < 0) { fullPath = directoryName + " \ " + theEntry.Name; fullPath = fullPath.Replace( " \ " , " \ " ); fullDirPath = Path .GetDirectoryName(fullPath); if (! Directory .Exists(fullDirPath)) { Directory .CreateDirectory(fullDirPath); } FileStream streamWriter = File .Create(fullPath); int size MessageBox.Show("Job Name:- " + Jobnam); if ( Directory .Exists(fullDirPath)) { pg = 0; foreach ( string tif_nam in Directory .GetFiles(fullDirPath, "*.tif" , SearchOption .AllDirectories)) { Image img = Bitmap .FromFile(tif_nam); int num = PageCount(img); if (num