- Home /
How to find the name of an xml I am opening
I am using this code:
//This should find how many .xml docs are in /data then create a button for each
DirectoryInfo dir = new DirectoryInfo(Application.dataPath + "/data");
FileInfo[] info = dir.GetFiles("*.xml");
foreach (FileInfo f in info) { NumMaps++; Debug.Log("Map found"); }
to find xml files in my data folder but how do I find and store the names of the file. Example : game.xml. How would I find that is called game?
Answer by kmeboe · Aug 11, 2012 at 06:40 PM
I'm not sure I completely understand your question. Are you trying to find the name of a file, with the extension stripped off? If this is the case, here's one way:
FileInfo file; // Let's say this has been populated with a file called "game.xml", as in your example loop
string baseName = System.IO.Path.GetFileNameWithoutExtension(file.Name);
At this point, the string "baseName" contains "game". Is that what you're looking for?
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Multiple Cars not working 1 Answer
C# Deserializing XML and Assigning Values 1 Answer
IsolatedStorageException: Could not find a part of the path 0 Answers
XML parsing c# in unity 1 Answer