我在本地文件夹中有这些文件。
从上图可以看到,其中有一个TMP文件。我不知道它是如何生成的,但是我相信它是一个无用的临时文件,因此我尝试通过以下方式将其删除:
foreach (var item in await ApplicationData.Current.LocalFolder.GetFilesAsync())
if (item.Name.EndsWith(".TMP"))
await item.DeleteAsync();
但是,既不使用GetFilesAsync()
也不使用GetItemsAsync()
找不到临时文件。前者仅提供json文件,而后者仅提供tmp文件。
我应该如何找到并删除它?
答案 0 :(得分:1)
您可以使用以下代码来检测隐藏文件在沙箱中的位置(仅在沙箱中起作用)。
winners = ["john", "anna", "max", "george"]
prizes = [(2, "peanuts"), (2, "carrot")]
s = "Congratulations to "
winners_index = 0
st = ""
for p in prizes:
i = 0
for w_in in range(winners_index,winners_index+p[0]):
print(w_in,i)
if i == 0:
st = st + s +winners[w_in]+','
elif i == p[0]-1:
st = st + winners[w_in]
else:
st = st + winners[w_in]+','
i = i + 1
st= st+ ' for winning '+p[1]+','
winners_index = winners_index + p[0]
用法
public static class ParseDir
{
public static FileInfo[] GetFilesFromDirectory(string DirName, string pattern, bool Recursive)
{
if (!Directory.Exists(DirName))
throw new Exception("No such Directory.");
DirectoryInfo dirInfo = new DirectoryInfo(DirName);
SearchOption Recur = Recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
return dirInfo.GetFiles(pattern, Recur);
}
public static FileInfo[] GetHiddenOnlyFiles(FileInfo[] Files)
{
List<FileInfo> result = new List<FileInfo>();
foreach (FileInfo file in Files)
if ((file.Attributes & System.IO.FileAttributes.Hidden) == System.IO.FileAttributes.Hidden)
result.Add(file);
return result.ToArray();
}
}