temporary-files

How can I unlock a file that is locked by a process in .NET [duplicate]

删除回忆录丶 提交于 2019-11-27 01:37:05
问题 This question already has an answer here: Unlock Files for deletion 2 answers I want my application to clean all the temp files it used, the problem is that not all the temp files are under my control, so I just want to "brutally" unlock them in order to delete them programatically. 回答1: Take a look at this article. I think that you'll struggle to do this in C# natively, even using interop, but writing a C++/CLI wrapper assembly may be a good compromise. Note also that the user needs to have

How can I create a temp file with a specific extension with .NET?

我只是一个虾纸丫 提交于 2019-11-26 23:29:12
I need to generate a unique temporary file with a .csv extension. What I do right now is string filename = System.IO.Path.GetTempFileName().Replace(".tmp", ".csv"); However, this doesn't guarantee that my .csv file will be unique. I know the chances I ever got a collision are very low (especially if you consider that I don't delete the .tmp files), but this code doesn't looks good to me. Of course I could manually generate random file names until I eventually find a unique one (which shouldn't be a problem), but I'm curious to know if others have found a nice way to deal with this problem.

catch on swipe to dismiss event

 ̄綄美尐妖づ 提交于 2019-11-26 21:37:37
I'm using an android notification to alert the user once a service is finished (success or failure), and I want to delete local files once the process is done. My problem is that in the event of failure - I want to let the user a "retry" option. and if he chooses not to retry and to dismiss the notification I want to delete local files saved for the process purposes (images...). Is there a way to catch the notification's swipe-to-dismiss event? Mr.Me DeleteIntent : DeleteIntent is a PendingIntent object that can be associated with a notification and gets fired when the notification gets

How do I automatically delete tempfiles in c#?

狂风中的少年 提交于 2019-11-26 18:59:02
问题 What are a good way to ensure that a tempfile is deleted if my application closes or crashes? Ideally I would like to obtain a tempfile, use it and then forget about it. Right now I keep a list of my tempfiles and delete them with an eventhandler that triggers on Application.ApplicationExit. Is there a better way? 回答1: Nothing is guaranteed if the process is killed prematurely, however, I use " using " to do this.. using System; using System.IO; sealed class TempFile : IDisposable { string

catch on swipe to dismiss event

女生的网名这么多〃 提交于 2019-11-26 17:26:58
问题 I'm using an android notification to alert the user once a service is finished (success or failure), and I want to delete local files once the process is done. My problem is that in the event of failure - I want to let the user a "retry" option. and if he chooses not to retry and to dismiss the notification I want to delete local files saved for the process purposes (images...). Is there a way to catch the notification's swipe-to-dismiss event? 回答1: DeleteIntent : DeleteIntent is a

Permission Denied To Write To My Temporary File

痴心易碎 提交于 2019-11-26 16:58:33
问题 I am attempting to create and write to a temporary file on Windows OS using Python. I have used the Python module tempfile to create a temporary file. But when I go to write that temporary file I get an error Permission Denied . Am I not allowed to write to temporary files?! Am I doing something wrong? If I want to create and write to a temporary file how should should I do it in Python? I want to create a temporary file in the temp directory for security purposes and not locally (in the dir

Creating temporary files in Android with NDK

大兔子大兔子 提交于 2019-11-26 16:34:04
问题 I am currently working on a C-based, NDK-based, Android application. This application needs to create temporary files. On a regular Linux system, I would use tmpfile to ensure that these files are properly created in a temporary directory and cleaned-up at process end. However, my investigations on various Android devices seem to indicate that tmpfile always fails; there is no /tmp directory; directory /data/local/tmp isn't present on all variants of Android; there is no TEMP environment

Creating temporary files in Android

為{幸葍}努か 提交于 2019-11-26 14:12:14
What's the best way to create a temporary file in Android? Can File.createTempFile be used? The documentation is very vague about it. In particular, it's not clear when temporary files created with File.createTempFile are deleted, if ever. This is what I typically do: File outputDir = context.getCacheDir(); // context being the Activity pointer File outputFile = File.createTempFile("prefix", "extension", outputDir); As for their deletion, I am not complete sure either. Since I use this in my implementation of a cache, I manually delete the oldest files till the cache directory size comes down

How to create a temp file in java without the random number appended to the filename?

纵然是瞬间 提交于 2019-11-26 11:19:58
问题 I need to create a temp file, so I tried this: String[] TempFiles = {\"c1234c10\",\"c1234c11\",\"c1234c12\",\"c1234c13\"}; for (int i = 0; i <= 3; i++) { try { String tempFile = TempFiles[i]; File temp = File.createTempFile(tempFile, \".xls\"); System.out.println(\"Temp file : \" + temp.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } } The output is something like this: Temp file : C:\\Users\\MD1000\\AppData\\Local\\Temp\\c1234c108415816200650069233.xls Temp file : C:\

How can I create a temp file with a specific extension with .NET?

。_饼干妹妹 提交于 2019-11-26 08:45:14
问题 I need to generate a unique temporary file with a .csv extension. What I do right now is string filename = System.IO.Path.GetTempFileName().Replace(\".tmp\", \".csv\"); However, this doesn\'t guarantee that my .csv file will be unique. I know the chances I ever got a collision are very low (especially if you consider that I don\'t delete the .tmp files), but this code doesn\'t looks good to me. Of course I could manually generate random file names until I eventually find a unique one (which