如何重定向到临时文件夹C#.NET [英] How do I redirect to temp folder C# .NET
问题描述
您好!我目前正在研究一种软件,它会删除我PC上的一些垃圾,我通常手动删除的东西,但因为我可以自动执行它为什么不正确?
我通常会删除我的临时文件夹中的所有内容..也就是说,如果你点击Windows Key + R并键入%temp%然后我删除那里的所有内容..事情是,我正在讨论这个问题我的一个朋友,我们同意这样的事情可能有用
Hello! I am currently working on a software that will delete some junk on my PC, stuff that I normally delete manually but since I can do it automaticlly why not right?
I usually delete everything in my temp folder.. That is if you hit the Windows Key + R and type %temp% and then I delete everything there.. The thing is, I was talking over this with a friend of mine and we agreed on something like this might work
System.IO.DirectoryInfo di = new DirectoryInfo("YourPath");
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
dir.Delete(true);
}
但问题是,他希望我给他发一次软件我已经完成..
我可以说我将YourPath更改为我的计算机上的确切路径它不会对他工作因为我说我的是
But the thing is, he wanted me to send him the software once im done..
And lets say I change the YourPath to the exact path on my computer it wont work on his because lets say mine is
C:\Users\Dev\AppData\Local\Temp
他的电脑上可能有不同的名字..
所以我的问题是..Is有一种方法可以在按下按钮时显示CMD或者是否有用于访问.NET库中临时文件的简短代码?
< b>我尝试了什么:
我试过看一下StackOverflow上的一些例子,但没有任何适用于我的情况..是的我是很清楚CCleaner
He might have a different name on his PC..
So my question is..Is there a way I could bring up maybe the CMD when a button is being pressed or is there a short code for accessing the temp files in the .NET library?
What I have tried:
I've tried looking over some examples on StackOverflow but nothing that applied to my situation.. And yes I am well aware of CCleaner
推荐答案
听起来你正在寻找 Path.GetTempPath方法 [ ^ ]:
Sounds like you're looking for the Path.GetTempPath method[^]:
string tempPath = Path.GetTempPath();
DirectoryInfo di = new DirectoryInfo(tempPath);
...
对我有用的是
What worked for me was
string tempPath = Path.GetTempPath();
DirectoryInfo di = new DirectoryInfo(tempPath);
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
这篇关于如何重定向到临时文件夹C#.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!