temporary-directory

Save image file to temp directory

余生长醉 提交于 2019-12-06 13:17:12
问题 I have an image file named "Image.png", and it is saved in my main bundle (right beside the ViewController.swift file in the Project Navigator hierarchy). I want to save a copy of this image to the temporary directory. I've never done it before, what code could I use please? 回答1: Something like this should do the trick. I'm assuming you wanted the answer in Swift. /** * Copy a resource from the bundle to the temp directory. * Returns either NSURL of location in temp directory, or nil upon

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

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);

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:

How should I handle exceptions in my Dispose() method?

假装没事ソ 提交于 2019-12-05 00:44:11
I'd like to provide a class to manage creation and subsequent deletion of a temporary directory. Ideally, I'd like it to be usable in a using block to ensure that the directory gets deleted again regardless of how we leave the block: static void DoSomethingThatNeedsATemporaryDirectory() { using (var tempDir = new TemporaryDirectory()) { // Use the directory here... File.WriteAllText(Path.Combine(tempDir.Path, "example.txt"), "foo\nbar\nbaz\n"); // ... if (SomeCondition) { return; } if (SomethingIsWrong) { throw new Exception("This is an example of something going wrong."); } } // Regardless of

Save image file to temp directory

眉间皱痕 提交于 2019-12-04 15:53:39
I have an image file named "Image.png", and it is saved in my main bundle (right beside the ViewController.swift file in the Project Navigator hierarchy). I want to save a copy of this image to the temporary directory. I've never done it before, what code could I use please? Something like this should do the trick. I'm assuming you wanted the answer in Swift. /** * Copy a resource from the bundle to the temp directory. * Returns either NSURL of location in temp directory, or nil upon failure. * * Example: copyBundleResourceToTemporaryDirectory("kittens", "jpg") */ public func

Possible to move the tmp directory of Eclipse?

送分小仙女□ 提交于 2019-12-04 06:32:39
I'm trying to speed up Eclipse by having my projects on a RAM disk (stuck with a slow laptop and a heavy kind of eclipse project at the moment). Worked great for loading the project and such, but when I'm building it seems to read and write a lot to a directory in %APPDATA% (seems to have a generated name from the name of the project). This makes it actually go slower than usual... So... is there a way I can move the tmp directory of eclipse? Preferably without moving the tmp directory of other applications in the process. May have found a way by setting a property called java.io.tmpdir in

Create a temporary directory in PowerShell?

≡放荡痞女 提交于 2019-12-03 10:31:54
PowerShell 5 introduces the New-TemporaryFile cmdlet , which is handy. How can I do the same thing but instead of a file create a directory? Is there a New-TemporaryDirectory cmdlet? Michael Kropat I think it can be done without looping by using a GUID for the directory name: function New-TemporaryDirectory { $parent = [System.IO.Path]::GetTempPath() [string] $name = [System.Guid]::NewGuid() New-Item -ItemType Directory -Path (Join-Path $parent $name) } Original Attempt With GetRandomFileName Here's my port of this C# solution : function New-TemporaryDirectory { $parent = [System.IO.Path]:

How to create a temporary directory and get the path / file name in Python

久未见 提交于 2019-12-03 01:14:09
问题 how to create a temporary directory and get the path / file name in python 回答1: Use the mkdtemp() function from the tempfile module: import tempfile import shutil dirpath = tempfile.mkdtemp() # ... do stuff with dirpath shutil.rmtree(dirpath) 回答2: To expand on another answer, here is a fairly complete example which can cleanup the tmpdir even on exceptions: import contextlib import os import shutil import tempfile @contextlib.contextmanager def cd(newdir, cleanup=lambda: True): prevdir = os

How to create a temporary directory and get the path / file name in Python

我怕爱的太早我们不能终老 提交于 2019-12-02 16:32:46
how to create a temporary directory and get the path / file name in python Philipp Use the mkdtemp() function from the tempfile module: import tempfile import shutil dirpath = tempfile.mkdtemp() # ... do stuff with dirpath shutil.rmtree(dirpath) To expand on another answer, here is a fairly complete example which can cleanup the tmpdir even on exceptions: import contextlib import os import shutil import tempfile @contextlib.contextmanager def cd(newdir, cleanup=lambda: True): prevdir = os.getcwd() os.chdir(os.path.expanduser(newdir)) try: yield finally: os.chdir(prevdir) cleanup() @contextlib