temporary-files

C++ tmpnam alternative

不问归期 提交于 2019-12-11 01:58:03
问题 I have a C++ library that uses tmpnam(NULL) to create a temporary file. I need to hack this because it makes the temp file in the root folder ("c:" or "/") and so it needs the administrative privileges. How can I change this function with other one using a valid temp path? Thanks. 回答1: Though tmpnam returns a filename pre-pended by / - it actually denotes a unique filename in the current directory and not / or c:\ . So you can chdir to any other directory before calling tmpnam to find a

Temp file that exists only in RAM?

大兔子大兔子 提交于 2019-12-11 01:56:03
问题 I'm trying to write an encrpytion using the OTP method. In keeping with the security theories I need the plain text documents to be stored only in memory and never ever written to a physical drive. The tmpnam command appears to be what I need, but from what I can see it saves the file on the disk and not the RAM. Using C++ is there any (platform independent) method that allows a file to exist only in RAM? I would like to avoid using a RAM disk method if possible. Thanks Edit: Thanks, its more

Batch- do more advanced calculations

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 01:04:53
问题 In batch, I have trouble doing more advanced calculations with set /a . Decimals won't work; for example set /a 5/2 only outputs 2 instead of 2.5 . Also batch can't handle large calculations. Is there a way to just make a temp file (like vbs) or call on another program (like calculator) to do the calculation and return it back to the batch file? 回答1: The program below as an example of a Batch-JScript hybrid script that allows to evaluate any JScript expression: @if (@CodeSection == @Batch)

Quick way to save a python TempFile?

南楼画角 提交于 2019-12-10 17:23:19
问题 I am using tempfile.TemporaryFile for some intermediate processing. The program nicely removes the temp file for me when it closes, which is precisely the behaviour that I want the majority of the time. But is there a way to save the file for examination in the event of a (trapped) error or other abnormal circumstance? 回答1: Seek to the beginning and use shutil.copyfileobj() to copy the data to a file you create. 回答2: Use tempfile.mkstemp() . According to the documentation: Unlike

Reusing the temporary file created by a file upload in a PHP form

旧时模样 提交于 2019-12-10 15:48:26
问题 regarding file uploads, I have a form through which I upload a file, I get the $temp_name = $_FILES['name']['temp_name'] and store it in a variable. Can I then use that variable again inside move_uploaded_file("$temp_name","$location") inside another form. Will this work?? When we upload a file, there is a temp location created on the server. How long can the temporary file be used for? Thanks. 回答1: You can only use that name in the script which receives the upload since the temporary file

Vim cannot save to temporary files created by python

限于喜欢 提交于 2019-12-10 15:27:22
问题 Goal I am trying to create and edit a temporary file in vim (exactly the same behavior as a commit script in git/hg/svn). Current code I found a method to do so in this answer: call up an EDITOR (vim) from a python script import sys, tempfile, os from subprocess import call EDITOR = os.environ.get('EDITOR','vim') initial_message = "write message here:" with tempfile.NamedTemporaryFile(suffix=".tmp") as tmp: tmp.write(initial_message) tmp.flush() call([EDITOR, tmp.name]) tmp.seek(0) print tmp

C/C++ Thread-safety of tmpnam?

丶灬走出姿态 提交于 2019-12-10 15:23:54
问题 I need to use the tmpnam function in C++, but I need to know about its thread safety. Namely, If I have several threads which will each need to acquire a different name for a temporary file, am I guaranteed that each thread will receive a file with a different name? 回答1: tmpnam only guarantees that the file did not exist at the time - but it may be created before you can do so yourself. To use it safely, you will ALWAYS need to then attempt to create the file with open (filename, O_CREAT | O

How do I prevent Visual Studio from creating obj folders in my source directory?

笑着哭i 提交于 2019-12-10 15:21:13
问题 I've set the OutputPath, IntermediateOutputPath, and BaseIntermediateOutputPath tags in all my csproj files. Despite that, Visual Studio creates extra "obj" folders in my source directories. As far as I can tell, it creates the directory obj\Debug\TempPE and then leaves it empty. I don't mind Visual Studio creating all sorts of crap, but how do I tell it to create it only in places where I want it, not in the source directory? 回答1: It is not possible to prevent Visual Studio 2008 from doing

Do temporary files get deleted even while the app is running?

倾然丶 夕夏残阳落幕 提交于 2019-12-10 14:39:01
问题 Background On android, you can create temporary files as such (link here and here for documentation) : final File temp = File.createTempFile("myFile", ".tmp", context.getCacheDir()); I'm developing an app that uses temporary files and when it's done with them (and on start of the app), it deletes them. The question The documentation says : When the device is low on internal storage space, Android may delete these cache files to recover space. Does it mean that files can get deleted even while

When a file created with mkstemp() is deleted?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 13:56:11
问题 I have a program that calls mkstemp(), writes some stuff with the fd returned and then closes the fd. I want the file to remain until I delete it myself! With something like rm command, or whatever. My question is: will Linux delete this file after close(fd)? 回答1: will Linux delete this file after close(fd)? Not automatically. You need to call unlink on the file manually. You can do this immediately after calling mkstemp if you don’t need to access the file by name (i.e. via the file system)