我有一段代码调用 Microsoft.VisualBasic.FileIO.FileSystem 类(在 Microsoft.VisualBasic 程序集中)中的 DeleteFile 方法,以便将文件发送到回收站而不是永久删除它。此代码位于托管 Windows 服务中,并在 Win Server 2k8 计算机(32 位)上运行。
相关行:
FileSystem.DeleteFile(file.FullName, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin, UICancelOption.DoNothing);
Run Code Online (Sandbox Code Playgroud)
当然,我有“using Microsoft.VisualBasic.FileIO;” 在类的顶部,我验证了被调用的方法确实位于该命名空间中的 FileSystem 类上。在上面的行中,我引用了一个本地变量“file” - 这是本地文件的 FileInfo(例如,C:\path\to\file.txt),我确信它存在。应用程序可以完全控制文件及其所在的目录。
当文件从其所在的目录中消失时,这似乎工作得很好。但是,该文件不会显示在回收站中。我尝试手动检查 C:\$Recycle.Bin 文件夹,因为我怀疑会话 0 中运行的 Windows 服务会使其最终进入不同的回收站,但所有回收站都显示为空。
有人知道导致这种行为的原因吗?
顺便说一句 - 机器上的相关驱动器(或任何其他驱动器)上绝对没有可用空间不足,并且文件非常小(几千字节,因此它不会超过回收站阈值)。
我的脚本创建文件以在运行时间内存储数据,我想在程序终止时删除这些文件.这可能吗?
我不想要一个解决方案的建议......比如'不要创建文件'.
非常感激!
我刚刚在我的Android-Project中删除了类R,我该如何取回它.我试图清理Project Setup,我创建了引用R的新文件但是没有任何作用.请帮帮我,我该怎么办?
最好的祝福
苹果浏览器
所以在我的代码中,我创建了一个音频输入流:
try{
File f = new File(main.getWavFileName(0, tab));
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(f);
audioInputStream.close();
audioInputStream = null;
f = null;
}catch(Exception e) {e.printStackTrace();}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试删除引用的文件时,出现 FileSystemException 错误,指出该文件正被另一个进程使用。当我注释掉上面的代码时,我不再收到错误并且能够删除文件。有没有办法强制 AudioInputStream 停止引用文件?
编辑:调用删除的代码 - 但是,我已经测试看到上面的代码在调用删除之前完成执行(只是在前后使用 system.out.print 以确保代码当前没有运行 - 不不知道更好的方法)
File f[] = new File(rootPath + File.separator + directoryNames.get(t)).listFiles();
for(File f2 : f)
{
try {
Files.delete(Paths.get(f2.getAbsolutePath()));
} catch (IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:仅供参考,我将 try 语句中的代码减少到您在上面看到的最低限度,但仍然出现错误,我不是无缘无故地尝试创建流。
编辑:我正在运行 Windows 7,但是当我注释掉代码时,删除文件没有任何错误。我得到的例外是:
java.nio.file.FileSystemException: C:\Users\Fred\Desktop\test patient\June 24th, 2011\s1.wav: The process cannot access the file because it is being …Run Code Online (Sandbox Code Playgroud) 我有 Windows 10 64 位
我尝试重新安装oracle数据库12c
我删除了所有文件..从目录..从服务。从regedit ..从temp ..从c盘..从任何地方我都删除了oracle文件我也运行了ccleaner但是当我再次尝试安装oracle database12c时
然后在这一步中显示 oraclehomeuser1 已经存在:O
我不知道为什么它位于哪里
请任何解决方案
我需要在 git log 中排除已删除的文件。我使用该命令git log -1 --name-only --pretty=format:eee6ce6在最后一次提交中获取更改的文件名。我使用pre-receive hook 来阻止特定的文件类型提交。上面的命令列出了所有修改过的文件。
但我想允许用户删除特定的文件类型。我怎样才能做到这一点?
git log -1 --name-only --pretty=format:eee6ce6-filter=d 命令,但它也列出了已删除的文件。git log -1 --diff-filter=d --name-only非常有效。但它commit ID, author name, date也给予。我只想要文件名。需要删除超过 7 天的 S3 中的文件,需要一个 shell 脚本来做到这一点,谷歌搜索不走运,我找到了下面的网址
http://shout.setfive.com/2011/12/05/deleting-files-older-than-specified-time-with-s3cmd-and-bash/
这对我们没有帮助,有人有删除超过 7 天的所有文件的脚本吗?
我想为我的delphi程序创建一个重置按钮.在我的程序中,有时会有一些Ini.pathexe中创建的文件.我现在要做的是创建一个按钮或标签,让我点击它以及何时点击它.它删除了我的pathexe中的所有.Ini文件
我怎么能这样做?
另外我想知道如何做一点'你确定吗?' 弹出,但这是一个小细节.
我在文件中写入一些文本,然后将其删除,但是删除失败。
代码很简单:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class TestFile {
public static void main(String[] args) throws IOException {
File file = new File("c:\\abc.txt");
writeFile(file, "hello");
// delete the file
boolean deleted = file.delete();
System.out.println("Deleted? " + deleted);
}
public static void writeFile(File file, String content) throws IOException {
OutputStream out = null;
try {
out = new FileOutputStream(file);
out.write(content.getBytes("UTF-8"));
} catch (IOException e) {
try {
out.close();
} catch (IOException e1) {
// ignored
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个内容菜单,当你在几秒钟内按下项目时,它会弹出一个重命名和删除菜单.但我不知道如何获得一个文件的正确目录.这是我的代码:
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
switch(item.getItemId()) {
case R.id.rename:
// edit stuff here
return true;
case R.id.delete:
File dir = new File(Environment.getExternalStorageDirectory()+"/Music/MusicPlayer");
if (dir.isDirectory())
{
String[] children = dir.list();
for (int i = 0; i < children.length; i++)
{
new File(dir, children[i]).delete();
}
}
// remove stuff here
return true;
default:
return super.onContextItemSelected(item);
}
}
Run Code Online (Sandbox Code Playgroud) delete-file ×10
java ×3
android ×2
file ×2
file-io ×2
.net ×1
amazon-s3 ×1
bash ×1
c# ×1
delphi ×1
git ×1
git-log ×1
ini ×1
oracle ×1
python ×1
recycle-bin ×1
termination ×1
windows-10 ×1