file-io

C# .NET - Is a deleted path a directory or file

How can I identify whether a deleted path was a file or a directory using C# .Net? thanks ...

ASP.NET MVC Request.Files not surviving Model.IsValid = false

I have a POST controller action like: if (ModelState.IsValid) { try { //.. save and redirect code here } catch { //.. add errors to model state } } return View(myModel); My request.files can contain 2 images from tags like: <input id="MyImage" name=...

Java: Check if file is already open

I need to write a custom batch File renamer. I've got the bulk of it done except I can't figure out how to check if a file is already open. I'm just using the java.io.File package and there is a canWrite() method but that doesn't seem to test if the file is in use by another program. Any ideas on how I can make this work? ...

Wait for file to be freed by process

How do I wait for the File to be Free so that ss.Save() can overwrite it with a new one. If I run this twice close together(ish) I get a generic GDI+ error. ///<summary> /// Grabs a screen shot of the App and saves it to the C drive in jpg ///</summary> private static String GetDesktopImage(DevExpress.XtraEditors.XtraFo...

How do you write a CSV in R with the matrix names (dimnames(M)) intact in R?

Is there a command in R that will allow you to write a CSV file that has the row and column names of a matrix (dimnames(M))? Whenever I output the file, the names are gone. help(write) doesn't mention that this is possible to do. ...

Encrypt and decrypt file in J2ME

Hi guys. I'm having problem decrypting an encrypted file in J2ME using bouncy castle. What I'm trying to do is select a file to encrypt,write the encrypted file and try decrypt it back to its orginal form (write to another file for verification purpose). I have this error when reading the encrypted file. Stack Trace : s: pad block cor...

C++ error when opening file

when I try to open a file for reading in my console application i get this error message: "Unhandled exception at 0x1048766d (msvcp90d.dll) in homework1.exe: 0xC0000005: Access violation writing location 0x00000000." It works fine when I compile and run the program on my macbook but when I run it on my desktop using VS 2008 it gives me ...

Reading/writing QObjects

I think I can write a QObject like this by taking advantage of the Q_PROPERTYs: QDataStream &operator<<(QDataStream &ds, const Object &obj) { for(int i=0; i<obj.metaObject()->propertyCount(); ++i) { if(obj.metaObject()->property(i).isStored(&obj)) { ds << obj.metaObject()->property(i).read(&obj); } } ...

How to implement/use a secure 'read-once' local file access system?

Hi, does anybody know of a secure 'read-once' local file access system? Or how one might create one? I realise that if data is to be used on a system, then it must be capable of being read, but I think it may be possible to severely limit how data is made available and reduce the possibility of it being copied and used elsewhere. These ...

How to read a float from binary file in C?

Everything I'm finding via google is garbage... Note that I want the answer in C, however if you supplement your answer with a C++ solution as well then you get bonus points! I just want to be able to read some floats into an array from a binary file EDIT: Yes I know about Endian-ness... and no I don't care how it was stored. ...

Is it a bad idea to put frequent file I/O operations within a SyncLock block?

Say I have some code that does this: Public Function AppendToLogFile(ByVal s As String) As Boolean Dim success As Boolean = True Dim fs As IO.FileStream = Nothing Dim sw As IO.StreamWriter = Nothing Static LogFileLock As New Object() SyncLock LogFileLock Try fs = New IO.FileStream(LogFilePath) ...

How to save a configuration file / python file IO

I have this python code for opening a .cfg file, writing to it and saving it: import ConfigParser def get_lock_file(): cf = ConfigParser.ConfigParser() cf.read("svn.lock") return cf def save_lock_file(configurationParser): cf = configurationParser config_file = open('svn.lock', 'w') ...

File Pointer Position

Here is the snippet of code typedef struct { double testA; double testB[500]; bool isProcessed; } MYSTURCT; I have a binary file which is written with multiple structs of type "myStruct". Now, in another function, I m trying to read the file and update in the middle. void test() { FILE* fp = fopen (testFile, "r+") ...

can we lock a directory?

Hello everyone, I am using VSTS 2008 + C# + .Net 3.5 to develop a console application. For file access, we can access file in exclusive mode which blocks other process/thread from access the file -- which has the effect of "lock" the file. I am wondering for directory, are there any built-in API or solution to make the directory exclus...

file enumerate issue

Hello everyone, I am using VSTS 2008 + C# + .Net 3.5 to develop a console application. I need to enumerate the most recent 50 files in current folder (to read file content, to get file meta data like file name, creation time, etc.). Since the current folder has about 5,000 files, and if I use Directory.GetFiles API, all 5,000 files' met...

File handling with non-administrative user.

I've been testing my application to see how well it works when run by a non-administrative user, and I have found problems with file handling. I am getting an UnauthorizedAccessException when trying to overwrite a file, if the file was created by and adminstrative user. When writing out the file I first create the file as a .tmp file, ...

Safely loading a hash in Ruby

I want to load a data structure into a Ruby script which maps a string to a triple which contains some combination of regular expressions, scripts and atoms. The file that it loads from needs to be human writeable. Currently I'm writing the file to contain a Ruby hash, loading that as a string and calling eval. Ie. Data file { "key1" ...

Reading license file from RLM with C# (C++ to C# translation)

I'm using the Reprise RLM license manager researching internet activation. I can't figure out how to get the license file from the webserver into a text file with C# (I'm also very new to C#). RLM comes with an example in C++ but I can't translate it. My code (for the demo) looks like so: int stat = RLM.rlm_act_request(handle, "http:/...

How to rollover the standard output from bash?

I have a script running in the background that prints some output. I redirected the standard output to a file for log purposes. However I don't want this file to grow forever, what would be a good way to do rollover without coding the logic myself? (Either rollover based on date or file size). ...

Why is nothing being written to a file?

I am creating and writing to a file using the following pattern: File afile = new File("C:/dev/ws/DataOrdering/data/" + thisDate + "_" + thisTime + "_visdata.csv"); FileWriter writer = new FileWriter(afile); writer.append(tradeDetails); writer.close(); However for some reason only the first file is written to, after that the files...