aewarnick Posted February 18, 2003 Posted February 18, 2003 I need a method that will enable me to get only the file names in a directory and put them as strings into a string array. Does anyone know something like that or close to it? Quote C#
Cywizz Posted February 18, 2003 Posted February 18, 2003 System.IO.Directory.GetFiles('enter path/search pattern here') will return a string array of files Quote Howzit??
aewarnick Posted February 19, 2003 Author Posted February 19, 2003 That returns a string with the path as well. I need just the file names. Quote C#
*Gurus* divil Posted February 19, 2003 *Gurus* Posted February 19, 2003 Use System.IO.Path.GetFilename(strFullPath) to get just the filename from a fully-qualified path. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted February 19, 2003 Author Posted February 19, 2003 string directory=house+"\\"+"CommLog"+date+"RTB"+(i+1); FileArr[0]=Path.GetFileNameWithoutExtension(directory); It only returns the name I already know(RTB1,RTB2,RTB3...). It does not return the names of the files in the folder. Another topic: How can I say "Get anything"? Ex: "c:\\folder\\"Get anything"\\file". Quote C#
Heiko Posted February 19, 2003 Posted February 19, 2003 When you have the fully qualified path plus filename in a string you can split the string with "\" as the splitter and the select the last element. pseudocode ahead Dim longName as string Dim shortName as string Dim parts() as string parts = split(longName, "\") shortName = parts(UBound(parts)) Quote .nerd
aewarnick Posted February 19, 2003 Author Posted February 19, 2003 That is VB not C#. And I need something that will not return any file name in any folder I specify no matter what the folder is. I think that can be done with Batch files like this: c:\folder\..\folder\.. Actually, that probably won't work, but you should get my point. Quote C#
*Experts* Volte Posted February 19, 2003 *Experts* Posted February 19, 2003 You want a function that doesn't return files? I really don't understand what you're looking for. Perhaps you should tell us what the program is that you are trying to make? Quote
aewarnick Posted February 19, 2003 Author Posted February 19, 2003 The program saves the documents as the names of the labels. That is why I need the names of the files and only the files (no extention) because I will use it to name the labels when the files are opened. Quote C#
*Experts* Volte Posted February 19, 2003 *Experts* Posted February 19, 2003 OK, so use the 'GetFiles' method (as shown above) to get the files into an array (this will include extensions). Then when you do need the filename without extension:Dim noExt, dummy As String For Each dummy In TheListOfFilesArray noExt = dummy.Split(".")(0) 'noExt contains the file w/o extension so do something with it here Next Quote
sethindeed Posted February 20, 2003 Posted February 20, 2003 Warning...the following is not catholic : Systen.Reflection.Assembly.GetExecutingAssembly.Location Quote What I don't know keeps me excited...
aewarnick Posted February 20, 2003 Author Posted February 20, 2003 Had to jump though some hoops for this one! FileArr=Directory.GetFiles(directory); MessageBox.Show(FileArr); string[]file=FileArr.Split('.'); int start=file.LastIndexOf("\\"); file=file.Substring(start+1); MessageBox.Show(file); Does anyone know the answer to the question posted in my other post above, about how I can say "any folder or file" in my code? Quote C#
aewarnick Posted February 20, 2003 Author Posted February 20, 2003 Here is what I wrote: And I need something that will not return any file name in any folder I specify no matter what the folder is. I think that can be done with Batch files like this: c:\folder\..\folder\.. Actually, that probably won't work, but you should get my point. Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.