delete-file

File.Delete the process cannot access the file because it is being used by another process

混江龙づ霸主 提交于 2021-02-17 06:51:22
问题 public bool DownloadMp3File (DownloadedMp3 mp3) { WebClient client = new WebClient (); string filePath = ""; bool wasDownload = false; try { string song = mp3.SongName; filePath = @"mp3\" + song + ".mp3"; if (File.Exists (filePath)) { File.Delete (filePath); } DateTime tryCountNow = DateTime.Now; client = new WebClient (); client.DownloadFileAsync (new Uri (mp3.Url), filePath); client.DownloadProgressChanged += client_DownloadProgressChanged; client.DownloadFileCompleted += client

How to delete the old files from a directory if a condition is true in PHP?

家住魔仙堡 提交于 2021-02-11 13:32:30
问题 I want to keep only 10 newest files in a folder and delete others. I created a script that deletes only the oldest ones if a file number is larger than 10. How can I adapt this script to my needs? $directory = "/home/dir"; // Returns array of files $files = scandir($directory); // Count number of files and store them to variable.. $num_files = count($files)-2; if($num_files>10){ $smallest_time=INF; $oldest_file=''; if ($handle = opendir($directory)) { while (false !== ($file = readdir($handle

Self Delete Folder with scripts powershell

非 Y 不嫁゛ 提交于 2021-02-08 06:38:13
问题 I have been trying to have powershell or batch scripts delete a folder that contains all my scripts when I am finished. Originally I tried Remove-Item -Path "C:\Tool" -Recurse -Force which worked no problem if run as a script for a location outside of C:\Tool . It would complain the files were in use when run from a script within. After some research I found &cmd.exe /c rd /s /q "C:\Tool" which worked much better, but even though I closed the GUI, the command wouldn't delete the img files

Self Delete Folder with scripts powershell

我的梦境 提交于 2021-02-08 06:36:44
问题 I have been trying to have powershell or batch scripts delete a folder that contains all my scripts when I am finished. Originally I tried Remove-Item -Path "C:\Tool" -Recurse -Force which worked no problem if run as a script for a location outside of C:\Tool . It would complain the files were in use when run from a script within. After some research I found &cmd.exe /c rd /s /q "C:\Tool" which worked much better, but even though I closed the GUI, the command wouldn't delete the img files

File.delete() does not completely delete image blank image file left behind

蓝咒 提交于 2021-02-06 09:12:41
问题 In my app you it takes a picture saves it to the SD card then user gets to chose what to do with it. Delete, save, or send. If you press delete. I call File.delete() it deletes the files when I go look in the gallery and then when I sometimes go back later I see a black image saying file cannot load. That image is the one I attempted to delete earlier. What is wrong with this and why doesn't it completely go away? How I save the image: public static File getOutputMediaFile(byte[] data){ image

Get a 0KB file after using PHP unlink() method

眉间皱痕 提交于 2021-02-05 11:17:48
问题 I'm trying to delete a file on the server. Below is the code I use. function ServerDel($file){ $file = realpath($file); echo ($file); $fh = fopen($file, 'w') or die("can't open file"); fclose($fh); if(unlink($file)) echo"Delete the file successfully."; else echo "Failed to delete."; } But after I run the code, the file still exists and becomes 0KB. Anyone knows how to get around this? 回答1: use a flag in fopen() instead of w . $fh = fopen($file, 'a') or die("can't open file"); Try this:

BASH - Delete files older than 3 months?

雨燕双飞 提交于 2021-02-04 13:39:47
问题 Delete files older than 3 months how? For 90 days i know: find /tmp/*.log -mtime +90 -type f -delete But how do i know 3 months equal to always 90 days? how many exact days? Is there more better way to tell the -mtime to follow months ? 回答1: If you want exact number of days for 3 months then you can use: days=$(( ( $(date '+%s') - $(date -d '3 months ago' '+%s') ) / 86400 )) and use it as: find /tmp/*.log -mtime +$days -type f -delete Or directly in find : find /tmp/*.log -type f \ -mtime "+$

BASH - Delete files older than 3 months?

喜夏-厌秋 提交于 2021-02-04 13:39:08
问题 Delete files older than 3 months how? For 90 days i know: find /tmp/*.log -mtime +90 -type f -delete But how do i know 3 months equal to always 90 days? how many exact days? Is there more better way to tell the -mtime to follow months ? 回答1: If you want exact number of days for 3 months then you can use: days=$(( ( $(date '+%s') - $(date -d '3 months ago' '+%s') ) / 86400 )) and use it as: find /tmp/*.log -mtime +$days -type f -delete Or directly in find : find /tmp/*.log -type f \ -mtime "+$

How to Stop OneNote API From Returning ID for Deleted Pages

血红的双手。 提交于 2021-01-29 22:09:51
问题 I place a call using the OneNote REST API to return a list of all the pages in a section. This works successfully. However, some of the pages it returns should no longer exist! Yet I can see their information, IDs, etc., even though they have previously been deleted. But if I try to delete them again using REST, I get the error: ERROR (deleteFromURL): <Response [404]> { "error":{ "code":"20102","message":"The specified resource ID does not exist.","@api.url":"http://aka.ms/onenote-errors

How to Stop OneNote API From Returning ID for Deleted Pages

邮差的信 提交于 2021-01-29 21:09:37
问题 I place a call using the OneNote REST API to return a list of all the pages in a section. This works successfully. However, some of the pages it returns should no longer exist! Yet I can see their information, IDs, etc., even though they have previously been deleted. But if I try to delete them again using REST, I get the error: ERROR (deleteFromURL): <Response [404]> { "error":{ "code":"20102","message":"The specified resource ID does not exist.","@api.url":"http://aka.ms/onenote-errors