file-io

Is it possible to read only the first line of a file with Actionscript?

I've got a PHP-based site where we allow users to upload a comma-separated text file of data to be imported by some server side scripts. However, sometimes we need to adjust the column order of the data that is uploaded, and it would be immensely helpful if we could identify the columns in the CSV file before the upload takes place. The...

Can I simply 'read' a file that is in use?

I am trying to use a StreamReader to read a file, but it is always in use by another process so I get this error: The process cannot access the file '\arfjwknasgmed17\C$\FLAG CONDITION\CP-ARFJN-FLAG.XLS' because it is being used by another process. Is there a way I can read this without copying it? Or is that my only option?...

I/O Performance Sanity Check - Checking for a file's existence

Are you aware of any serious performance problems with checking if a file exists before you open it and send it? The context for this is a web application that serves up files dynamically via an ASP page. I was told that there is no check for whether or not the file exists because the database stores this information and shouldn't be wro...

What is the best way to slurp a file into a string in Perl?

Yes, There's More Than One Way To Do It but there must be a canonical or most efficient or most concise way. I'll add answers I know of and see what percolates to the top. To be clear, the question is how best to read the contents of a file into a string. One solution per answer. ...

How gmail handles file attachment?

Hi, When I select a file to attach in gmail compose screen, It automatically uploads the file to server without page refresh. I looked at the html source code via FireBug and have not seen a n iframe. How do they upload attachments? Thanks. ...

Validate image from file in C#

I'm loading an image from a file, and I want to know how to validate the image before it is fully read from the file. string filePath = "image.jpg"; Image newImage = Image.FromFile(filePath); The problem occurs when image.jpg isn't really a jpg. For example, if I create an empty text file and rename it to image.jpg, an OutOfMemory Ex...

How do I create a temporary file with Cocoa?

Years ago when I was working with C# I could easily create a temporary file and get its name with this function: Path.GetTempFileName(); This function would create a file with a unique name in the temporary directory and return the full path to that file. In the Cocoa API's, the closest thing I can find is: NSTemporaryDirectory A...

How to avoid File Blocking

We are monitoring the progress of a customized app (whose source is not under our control) which writes to a XML Manifest. At times , the application is stuck due to unable to write into the Manifest file. Although we are covering our traces by explicitly closing the file handle using File.Close and also creating the file variables in Us...

Only allow one server to access a file on a network drive

I have an application running on multiple IIS servers that need to parse a CSV file that is placed on a common network drive. If I use the System.IO.FileSystemWatcher Created event to be notified of the event when the file is available, how can I ensure only one server parses the file? If all servers are notified of this change, all wi...

In C#, if 2 processes are reading and writing to the same file, what is the best way to avoid process locking exceptions?

With the following file reading code: using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None)) { using (TextReader tr = new StreamReader(fileStream)) { string fileContents = tr.ReadToEnd(); } } And the following file write code: using (TextWriter tw = new StreamWriter(f...

Batch Renaming of Files in a Directory

Is there an easy way to rename a group of files already contained in a directory, using Python? Example: I have a directory full of *.doc files and I want to rename them in a consistent way. X.doc -> "new(X).doc" Y.doc -> "new(Y).doc" ...

What do PHP stream contexts do in relation to file operations?

In the PHP manual, the file operations reference an optional context (e.g. for copy). How do these contexts affect basic file operations? ...

How do you copy a file in PHP without overwriting an existing file?

When you use the PHP copy function, the operation blindly copies over the destination file, even if it already exists. How do you copy a file safely, only performing the copy if there is no existing file? ...

Removing file locks

I need to recover form an error case where a file gets left in a locked state. How can I in c# tell this file to reset it's locks? I need to add to this the file is opened by a 3rd party dll and I don't actually have access to the file handle. ...

Difference between files writen in binary and text mode

What translation occurs when writing to a file that was opened in text mode that does not occur in binary mode? Specifically in MS Visual C. unsigned char buffer[256]; for (int i = 0; i < 256; i++) buffer[i]=i; int size = 1; int count = 256; Binary mode: FILE *fp_binary = fopen(filename, "wb"); fwrite(buffer, size, count, fp_binary)...

write a file from webservices

hi I have a webservice using .net c# and I want to write to a text file on the server, but I cannot get this to work I assume it is a permission problem? thanks Stuart I think the problem is I am using System.IO.Directory.GetCurrentDirectory() what should I be using? thanks Stuart ...

creating application shortcut in a directory

How do you create an application shortcut (.lnk file) in C# or using the .NET framework? The result would be a .lnk file to the specified application or URL. ...

How do you determine the ideal buffer size when using FileInputStream?

I have a method that creates a MessageDigest (a hash) from a file, and I need to do this to a lot of files (>= 100,000). How big should I make the buffer used to read from the files to maximize performance? Most everyone is familiar with the basic code (which I'll repeat here just in case): MessageDigest md = MessageDigest.getInstance(...

Whats the 'best' method of writing data out to a file, to be later read in again. (C++)

Hi, What is the best way of storing data out to a file on a network, which will be later read in again programmatically. Target platform for the program is Linux (Fedora), but it will need to write out a file to a Windows (XP) machine This needs to be in C++, there will be a high number of write / read events so it needs to be efficien...

CFile Error On Windows Ce

I am using Windows CE 4.2 and MS Embedded VC++ 4.0. The following code gives me the error Access to [file name] was denied., and it creates the file but does not write anything to it. CString tmp; tmp.Format(_T("%s%d"), mFileName, ++ctr); TRY { mFile.Open(tmp, CFile::modeCreate); mFile.Write(&data[ctr%2], 1); mFile.Close(); } CA...