delete-file

How to delete files of a directory but not the folders

有些话、适合烂在心里 提交于 2019-12-19 10:26:17
问题 I have create some code that deletes all the files in a folder, the issue is while this is great, I want to be able to delete all the files in a directory but leave the folders intact, so I do not have to go into each folder and delete the files in it, this is my current code : @ViewScoped @ManagedBean public class Delete { public void DeleteFiles() throws IOException { System.out.println("Called deleteFiles"); File file = new File("D:/Documents/NetBeansProjects/printing~subversion/fileupload

How to delete multiple files at once using Google Drive API

心不动则不痛 提交于 2019-12-19 09:10:13
问题 I'm developing a python script that will upload files to a specific folder in my drive, as I come to notice, the drive api provides an excellent implementation for that, but I did encountered one problem, how do I delete multiple files at once? I tried grabbing the files I want from the drive and organize their Id's but no luck there... (a snippet below) dir_id = "my folder Id" file_id = "avoid deleting this file" dFiles = [] query = "" #will return a list of all the files in the folder

How to avoid UNLINK security risks in PHP?

此生再无相见时 提交于 2019-12-19 07:44:09
问题 I'm using UNLINK with PHP and AJAX . I know that in this way is very dangerous, because everyone can delete any files. But I need to use AJAX because I can't reload the page when I delete the files. So how should I do to allow to delete the file only for the user who owns it? Please let me know other things too if you think I'm doing here something wrong or something else what you have in mind and you think that it will be useful : ) My PHP code: <?php $photo_id = $_GET['photo_id'];

Java.nio: most concise recursive directory delete

柔情痞子 提交于 2019-12-18 10:54:23
问题 I am currently trying to recursively delete a directory... Strangely enough the shortest piece of code I was able to find is the following construct, employing an ad-hoc inner class and in a visitor pattern ... Path rootPath = Paths.get("data/to-delete"); try { Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { System.out.println("delete file: " + file.toString()); Files.delete(file

java Cannot delete file, being used by another process

你说的曾经没有我的故事 提交于 2019-12-18 09:04:35
问题 I have this code import org.apache.commons.io.FileUtils; try { FileUtils.copyURLToFile(new URL(SHA1_LINK), new File("SHA1.txt")); if(!sameSha1()) { System.out.println("sha diferentes"); FileUtils.copyURLToFile(new URL(LINK), new File(PROG)); } } catch (Exception e) { System.out.println("Internet is off"); } //delete SHA1 file Files.deleteIfExists(Paths.get("SHA1.txt")); and when I execute it it says java.nio.file.FileSystemException The process cannot access the file because it is being used

How to delete many 0 byte files in linux?

天大地大妈咪最大 提交于 2019-12-17 17:26:06
问题 I've a directory with many number of 0 byte files in it. I can't even see the files when I use the ls command. I'm using a small script to delete these files but sometimes that does not even delete these files. Here is the script: i=100 while [ $i -le 999 ];do rm -f file${i}*; let i++; done Is there any other way to do this more quickly? 回答1: Use find combined with xargs . find . -name 'file*' -size 0 -print0 | xargs -0 rm You avoid to start rm for every file. 回答2: With GNU's find (see

Deleting directory in Python

主宰稳场 提交于 2019-12-17 10:55:25
问题 shutil.rmtree will not delete read-only files on Windows. Is there a python equivalent of "rm -rf" ? Why oh why is this such a pain? 回答1: shutil.rmtree can take an error-handling function that will be called when it has problem removing a file. You can use that to force the removal of the problematic file(s). Inspired by http://mail.python.org/pipermail/tutor/2006-June/047551.html and http://techarttiki.blogspot.com/2008/08/read-only-windows-files-with-python.html: import os import stat

How to make .BAT file delete it self after completion?

久未见 提交于 2019-12-17 06:33:41
问题 How to make .BAT file delete it self after completion? I have a simple bat file that terminates a process. I want that .BAT file to delete itself. 回答1: @ECHO OFF SETLOCAL SET someOtherProgram=SomeOtherProgram.exe TASKKILL /IM "%someOtherProgram%" ECHO "This script will now self-destruct. Please ignore the next error message" DEL "%~f0" Note that the DEL line better be the last thing you intend to execute inside the batch file, otherwise you're out of luck :) This will print out an ugly error

Deleting a file in VBA

谁都会走 提交于 2019-12-17 03:01:06
问题 Using VBA, how can I: test whether a file exists, and if so, delete it? 回答1: 1.) Check here. Basically do this: Function FileExists(ByVal FileToTest As String) As Boolean FileExists = (Dir(FileToTest) <> "") End Function I'll leave it to you to figure out the various error handling needed but these are among the error handling things I'd be considering: Check for an empty string being passed. Check for a string containing characters illegal in a file name/path 2.) How To Delete a File. Look

Deleting a file in VBA

懵懂的女人 提交于 2019-12-17 03:00:45
问题 Using VBA, how can I: test whether a file exists, and if so, delete it? 回答1: 1.) Check here. Basically do this: Function FileExists(ByVal FileToTest As String) As Boolean FileExists = (Dir(FileToTest) <> "") End Function I'll leave it to you to figure out the various error handling needed but these are among the error handling things I'd be considering: Check for an empty string being passed. Check for a string containing characters illegal in a file name/path 2.) How To Delete a File. Look