August 17th, 2010 05:57 PM
#1
[RESOLVED] Check Directory for xml file
How do I simply check a directory to make sure there is a xml file there?? I don't need to load it > psuedo code
Code:
try
{
string location = @"\My Documents\My Games\Something\Something";
check for (".xml");
}
catch
{
exception
}
August 17th, 2010 06:50 PM
#2
Re: Check Directory for xml file
System.IO.File.Exists(string filename)
Your Google-fu is weak young padawan....
August 17th, 2010 07:11 PM
#3
Re: Check Directory for xml file
August 17th, 2010 10:06 PM
#4
Re: Check Directory for xml file
I got a problem
I am using this as the argument
Code:
if (File.Exists(GameRef.GetDocumentsDirectory + @"\My Documents\My Games\RPGBXL" + "*.xml"))
{
manager.ChangeScreens(GameRef.PopUpScreenLoadFile);
}
else
{
BeginException = true;
}
only problem is - IF there is a xml document there - Which there is, it still going to the exception
August 18th, 2010 12:54 AM
#5
Re: Check Directory for xml file
Looks like you are missing a backslash at the end of your path
Unless you are looking for RPGBXL*.xml
Always use [code][/code] tags when posting code.
August 18th, 2010 02:46 AM
#6
Re: Check Directory for xml file
Pretty sure you can't pass a wild card to that method either. In the case of looking for any .xml file, use Directory.GetFiles.
August 18th, 2010 09:54 AM
#7
Re: Check Directory for xml file
Hi Bixel,
Hope below code helps yo.. even yo need to search for txt files change the *xml to *txt
DirectoryInfo dir = new DirectoryInfo(@"C:\Data");
FileSystemInfo[] files = dir.GetFileSystemInfos("*xml");
foreach (FileSystemInfo info in files)
{
Console.WriteLine(info.FullName);
}
August 18th, 2010 06:43 PM
#8
Re: Check Directory for xml file
to : ramkumarradhakrishnan
That helped A LOT!!!
here is successful code
Code:
DirectoryInfo dir = new DirectoryInfo(GameRef.GetDocumentsDirectory + @"\My Documents\My Games\RPGBXL");
FileSystemInfo[] files = dir.GetFileSystemInfos("*xml");
if(files[0] != null)
{
manager.ChangeScreens(GameRef.PopUpScreenLoadFile);
}
else
{
BeginException = true;
}
Thanks!
Last edited by bixel; August 18th, 2010 at 07:21 PM .
Reason: solved
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks