How can I force this method to return the next xml file name in the folder after it's contents change



I'm getting my file names, randomly I believe, but getting them with this.



public static string getXMLrequestFileNames()
{
string path = requestsFolder;
fileName = "";

int count = 0;

foreach (string s in Directory.GetFiles(path, "*.xml").Select(Path.GetFileName))
{

fileName = "\\" + s;
count++;
}
return fileName;
}


I place the file name in a string and hold it for deletion. When I delete the file with the following code, I'm still seeing the last file name from above.



private static void deleteRequest()
{
string curFileWeekDelete = (filename);
bool test = false;

if (File.Exists(requestsFolder + curFileWeekDelete))
{
string[] getAppPaths = Directory.GetFiles(requestsFolder);

test = getAppPaths.Contains(requestsFolder + curFileWeekDelete);
foreach (string getAppPath in getAppPaths)
if (test == true)
{
File.Delete(requestsFolder + curFileWeekDelete);
//filename = "";
}
}
}


Once the file is deleted I run through getXMLrequestFileNames() again. The next file loads appropriately but the file name being found is the deleted file name?? Can someone please point me in the right direction?? Thank you very much in advance


No comments:

Post a Comment