temporary-files

Why is the WindowsError while deleting the temporary file?

↘锁芯ラ 提交于 2019-12-06 00:49:03
I have created a temporary file. Added some data to the file created. Saved it and then trying to delete it. But I am getting WindowsError . I have closed the file after editing it. How do I check which other process is accessing the file. C:\Documents and Settings\Administrator>python Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tempfile >>> __, filename = tempfile.mkstemp() >>> print filename c:\docume~1\admini~1\locals~1\temp\tmpm5clkb >>> fptr = open(filename, "wb") >>>

Python tempfile.TemporaryFile hangs on Windows when no write privilege

﹥>﹥吖頭↗ 提交于 2019-12-05 19:05:22
My environment is Python 3.7.2, running on Windows 10. I'm working on a directory-selection widget, and I'm looking for the cleanest+surest method to test whether the selected directory path allows write privilege. Previously I'd been opening a named file by the usual open() method, writing a few bytes to it, then deleting it -- putting the whole thing in a try-except block. This was OK but it ran the risk of leaving behind an unwanted file. Recently I came across the documentation for tempfile.TemporaryFile() , and this seemed cleaner way to get the same result, with no risk of leaving junk

How to add image into a post in django

…衆ロ難τιáo~ 提交于 2019-12-05 17:52:59
I'm building an blog system, which allow user add image to their blog. when user add image, the image will be upload automatically, this happened before the blog is posted, so how should I handle the uploaded image, these image is kind of like temporary image, because if the user post the blog, these images will have an foreign key to this blog , and saved into some folder,but if the user discard the blog , these temporary images should be deleted. the problem is how to get the firstly uploaded images,when the blog is actually posted? where should I store these temporary images? and how can I

Create directory inside NSTemporaryDirectory

你离开我真会死。 提交于 2019-12-05 12:58:36
How can I create a directory inside NSTemporaryDirectory ? I tried something like: [NSTemporaryDirectory() stringByAppendingPathComponent:@"/myTmp/"]; followed by the file name, but it didn't work. Use NSFileManager to create the directory for you: [[NSFileManager defaultManager] createDirectoryAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"/myTmp/"] withIntermediateDirectories:YES attributes:nil error:nil]; 来源: https://stackoverflow.com/questions/6847788/create-directory-inside-nstemporarydirectory

Python: How do I make temporary files in my test suite?

对着背影说爱祢 提交于 2019-12-05 11:57:13
问题 (I'm using Python 2.6 and nose .) I'm writing tests for my Python app. I want one test to open a new file, close it, and then delete it. Naturally, I prefer that this will happen inside a temporary directory, because I don't want to trash the user's filesystem. And, it needs to be cross-OS. How do I do it? 回答1: See the tempfile module in the standard library -- should be all you need. 回答2: FWIW using py.test you can write: def test_function(tmpdir): # tmpdir is a unique-per-test-function

C# Best Practices: Writing “temporary” files for download: Place in applicaion's environment folder or temp folder

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 11:55:10
Basically, I'm wondering if there is a best practice when it comes to the following issue of downloading files, not just for temporary use, but eventually to move them to the application folder. I'm faced with some options: //Option 1 - Random file String tempfile = Path.GetTempFileName(); WriteData(tempfile); File.Move(tempfile, Path.Combine(Environment.CurrentDirectory, filename); //Option 2 - Temp Path + Random file name String tempfile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); WriteData(tempfile); File.Move(tempfile, Path.Combine(Environment.CurrentDirectory, filename);

Is createTempFile thread-safe?

末鹿安然 提交于 2019-12-05 10:47:47
I'm using Java 6. Is it possible that two threads calling createTempFile (of the class java.io.File) get the same temp file? Best way to get your answer is to look at the source code. At first there isn't any synchronization in createTempFile, but to generate the temp file name, it is using SecureRandom which is ThreadSafe. Then unless you are really unlucky, your file will always get a different name. On top of that, createTempFile implementation is looping, generating new file name, until the file has been created. The file creation of course is delegated to the native file system operation

Real file objects slower than StringIO and cStringIO?

别等时光非礼了梦想. 提交于 2019-12-05 07:29:01
问题 StringIO has the following notes in its code: Notes: - Using a real file is often faster (but less convenient). - There's also a much faster implementation in C, called cStringIO, but it's not subclassable. The "real file is often faster" line seemed really odd to me: how could writing to disk beat writing to memory? I tried profiling these different cases and got results that contradict these docs, as well as the answer to this question. This other question does explain why cStringIO is

How can I get the default file permissions in Python?

岁酱吖の 提交于 2019-12-05 05:49:12
I am writing a Python script in which I write output to a temporary file and then move that file to its final destination once it is finished and closed. When the script finishes, I want the output file to have the same permissions as if it had been created normally through open(filename,"w") . As it is, the file will have the restrictive set of permissions used by the tempfile module for temp files. Is there a way for me to figure out what the "default" file permissions for the output file would be if I created it in place, so that I can apply them to the temp file before moving it? For the

When does iOS clean the local app ./tmp directories?

自闭症网瘾萝莉.ら 提交于 2019-12-05 03:51:20
When does iOS clean the local app ./tmp directory? Note that this is not a dupe of this question . I'm asking about the app specific temporary folder, not the system wide one. You can use iExplorer to have a look at ./tmp directories on non-jailbroken phones. (Note: I'm asking this out of curiosity only. I kind of suspect that these never get deleted unless you restore your phone from a backup or reinstall that particular app. But obviously you cannot count on that for semi-permanently storing cached files. ) According to the documentation , it could be any time, if the app is not executing: