delete-file

Prevent a user from deleting, moving or renaming a file

十年热恋 提交于 2019-11-30 18:25:11
What I am trying to do is while my program is using a file, I want to keep the user from renaming, deleting, or moving the file (well... a move is a delete and a create at a different location according to Windows FileSystemWatcher , but I digress). It has been suggested that I use FileStream.Lock or use a Mutex . However, FileStream.Lock seems only to prevent the file from being modified which I am trying to allow . Also, I am very unsure as to if a mutex can lock a file, although I am still reading on it with in the .Net 4.0 library. Does anyone have any advice on utilizing either one and if

Bizarre directory delete behaviour on SSD drive

谁说胖子不能爱 提交于 2019-11-30 17:15:09
Directory c:\test has 50 or so files in it, no subdirectories. If IO.Directory.Exists("C:\test") Then IO.Directory.Delete("C:\test", True) End If IO.Directory.CreateDirectory("C:\test") Drive C is Intel's X25-M80 SSD drive, OS is Windows 7 64 bit with TRIM support, Visual Studio is 2008 with target framework 3.5. When above code is executed, CreateDirectory breaks code execution without an (visible) exception. After much headache I found that Delete is not yet done by the time code execution gets to CreateDirectory. If I modify my code like this: If IO.Directory.Exists("C:\test") Then IO

Git ignore deleted files

浪子不回头ぞ 提交于 2019-11-30 12:53:00
问题 I have a website project that has more than 50,000 unimportant files (to development) in some directories. /website.com/files/1.txt /website.com/files/2.txt /website.com/files/3.txt /website.com/files/etc.txt The stuff in /files is already in the repo. I want to delete all the files in /files on my local copy but I want git to ignore it so it doesn't delete them when I do a pull on the web server. Any ideas? 回答1: Ignoring a whole directory didn't work. I had to do this: for i in `git status |

How to delete or purge old files on S3?

限于喜欢 提交于 2019-11-30 11:43:04
问题 Are there existing solutions to delete any files older than x days? 回答1: Amazon has introduced object expiration recently. Amazon S3 Announces Object Expiration Amazon S3 announced a new feature, Object Expiration that allows you to schedule the deletion of your objects after a pre-defined time period. Using Object Expiration to schedule periodic removal of objects eliminates the need for you to identify objects for deletion and submit delete requests to Amazon S3. You can define Object

Force Delete all files from a folder

跟風遠走 提交于 2019-11-30 11:41:15
I have been using a specific piece of code to delete files from a folder but it is proving very problematic because maybe I forgot to close an InputStream or two. The code I have is so big that I am not be able to see all the Inputstreams that I have not closed. Is there a way of deleting files whether there is an open InputStream or not? This is the piece of the code that I have been using; File fin = new File("C:/ABC Statements final/"); File[] finlist = fin.listFiles(); for (int n = 0; n < finlist.length; n++) { if (finlist[n].isFile()) { System.gc(); Thread.sleep(2000); finlist[n].delete()

Python Deleting Certain File Extensions

孤人 提交于 2019-11-30 10:01:29
I'm fairly new to Python, but I have gotten this code to work, and in fact, do what it's intended to do. However, I'm wondering if there is a more efficient way to code this, perhaps to enhance the processing speed. import os, glob def scandirs(path): for currentFile in glob.glob( os.path.join(path, '*') ): if os.path.isdir(currentFile): print 'got a directory: ' + currentFile scandirs(currentFile) print "processing file: " + currentFile png = "png"; jpg = "jpg"; if currentFile.endswith(png) or currentFile.endswith(jpg): os.remove(currentFile) scandirs('C:\Program Files (x86)\music\Songs')

Deleting file from FTP in C#

∥☆過路亽.° 提交于 2019-11-30 08:40:41
My program can upload files into an FTP server using this code: WebClient client = new WebClient(); client.Credentials = new System.Net.NetworkCredential(ftpUsername, ftpPassword); client.BaseAddress = ftpServer; client.UploadFile(fileToUpload, WebRequestMethods.Ftp.UploadFile, fileName); Right now I need to delete some files and I can't do that right. What should I use instead of client.UploadFile(fileToUpload, WebRequestMethods.Ftp.UploadFile, fileName); You'll need to use the FtpWebRequest class to do that one, I think. FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri); /

Google apps script : How to Delete a File in Google Drive?

主宰稳场 提交于 2019-11-30 08:34:31
How do I write a Google Apps Script that deletes files? This finds files: var ExistingFiles = DocsList.find(fileName); But DocsList.deleteFile does not exist to delete a file. Is there a way to move those files to another Folder or to Trash? The other workaround I would consider is to be able to override an existing file with the same name. Currently when I want to create a file with a name already used in MyDrive then it creates a second file with the same name. I would like to keep 1 file (the new one is kept and the old one is lost). The DocsList service is now deprecated. This answer uses

Waiting for system to delete file

◇◆丶佛笑我妖孽 提交于 2019-11-30 08:06:34
问题 I had a problem with refreshing file list after deleting a file. When I gave command to delete file, the exception was thrown because the refresh method tried to access a file that was supposed to be deleted. After some thought and debuging I came to conclusion that problem was in a fact that system needs some time to delete a file. And I solve it like this: //Deleting file System.Threading.Thread.Sleep(2000); //Refreshing list and it worked fine. My question is Is there a more elegant way to

Auto delete all files after x-time

北慕城南 提交于 2019-11-30 07:17:48
How do you auto delete all files under a sub directory after x-time (let say after 24 hours) - without using a cronjob command from server or pl. How can you do this just using PHP code or by just visiting the page without clicking something and the command auto runs. Response for last comment from my first answer. I'm going to write code sample, so I've created another answer instead of addition one more comment. To remove files with custom extension you have to implement code: <?php $path = dirname(__FILE__).'/files'; if ($handle = opendir($path)) { while (false !== ($file = readdir($handle)