file-io

How to search through archived files with Perl

What is your preferred method for reading through the contents of zipped directories with Perl ? ...

Get last n lines of a file with Python, similar to tail

I'm writing a log file viewer for a web application and for that I want to paginate through the lines of the log file. The items in the file are line based with the newest item on the bottom. So I need a tail() method that can read n lines from the bottom and supports an offset. What I came up with looks like this: def tail(f, n, off...

How do I read a file in C++?

I am having some problems reading from a file. I have two header files: a and b. b is derived from a,and c is derived from b. Now i want to open a text file. The whole format is like this: A john A johnee P 123 If the first charcter is 'a' and 'p' is also there, then print the second line, else print the first line. #i...

Checking File is Open in Delphi

Is there a way to check if a file has been opened by ReWrite in Delphi? Code would go something like this: AssignFile(textfile, 'somefile.txt'); if not textFile.IsOpen then Rewrite(textFile); ...

How do you write the end of a file opened with FILE_FLAG_NO_BUFFERING?

I am using VB6 and the Win32 API to write data to a file, this functionality is for the export of data, therefore write performance to the disk is the key factor in my considerations. As such I am using the FILE_FLAG_NO_BUFFERING and FILE_FLAG_WRITE_THROUGH options when opening the file with a call to CreateFile. FILE_FLAG_NO_BUFFERING ...

What is the best way to write to a file in Ruby?

I would like to write some data to a file in Ruby. What is the best way to do that? ...

How much is File I/O a performance factor in web development?

I know the mantra is that the database is always the long pole in the tent anytime a page is being generated server-side. But there's also a good bit of file i/o going on on a web server. Scripted code is replete with include/require statements. Moreover, its typically a practice to store templated html outside the application in files ...

Perl: Grabbing the nth and mth delimited words from each line in a file

Because of the more tedious way of adding hosts to be monitored in Nagios (it requires defining a host object, as opposed to the previous program which only required the IP and hostname), I figured it'd be best to automate this, and it'd be a great time to learn Perl, because all I know at the moment is C/C++ and Java. The file I read...

How to check if there is any read/write activity for a specific harddrive with C#?

I'm curious how to assess if there is any read- or write-activity for a specific harddrive at a given moment with .NET / C#. Second it would be interesting to assess the actual speed of access. Any ideas? ...

Using Quotes within getRuntime().exec

Hi, I'd like to invoke bash using a string as input. Something like: sh -l -c "./foo" I'd like to do this from Java. Unfortunately, when I try to invoke the command using getRuntime().exec, I get the following error: foo": -c: line 0: unexpected EOF while looking for matching `"' foo": -c: line 1: syntax error: unexp...

How to evict file from system cache on Linux?

When running performance tests file system cache hit or miss can significantly influence test results. Therefore generally before running such tests used files are evicted from system cache. How to do that on Linux? Clarification: If possible, the solution should not require root privileges. ...

StreamWriter: Max Write Length?

Is there a max length that a stream writer can write out to a file? Or is there a max length that WriteLine() can output? I am trying to write some data to a file but all of the data does not seem to make it. Thank you for the help ...

Problem with relative paths C#

I got following problem my app open file in subdirectory of directory where it is executed, subdirectory is called sample and it contains files example.raf (example extension, non signigficant) background.gif example.raf contains relative path to background.gif (in this case only file name cause the files is in same directory as raf)...

Performance of System.IO.ReadAllxxx / WriteAllxxx methods

Is there any performance comparison of System.IO.File.ReadAllxxx / WriteAllxxx methods vs StreamReader / StremWriter classes available on web. What you think is the best way(from a performance perspective) to read/write text files in .net 3.0? When I checked the MSDN page of System.IO.File class, in the sample code MS is using StreamRea...

Using PHP to take the first line of a CSV file and create a MySQL Table with the data

I am trying to take a rather large CSV file and insert it into a MySQL database for referencing in a project. I would like to use the first line of the file to create the table using proper data types and not varchar for each column. The ultimate goal is to automate this process as I have several similar files but the each has different ...

Simplest, efficient ways to read binary and ascii files to string or similar in various languages.

Personally, I always forget this stuff. So I figured this is a useful thing to have as a reference. Read an ascii file into a string Write an ascii file from a string Read a binary file into something appropriate. If possible, store in a string, too. Write a binary file from something appropriate. If possible, write from a string, t...

What is the most elegant way to read a text file with c++?

Hi, I'd like to read whole content of a text file to a std::string object with c++. With Python, I can write: text = open("text.txt", "rt").read() It is very simple and elegance. I hate ugly stuff, so I'd like to know what is the most elegance way to read a text file with c++? Thanks. ...

Design: Large archive file editor, file mapping

Hello! I'm writing an editor for large archive files (see below) of 4GB+, in native&managed C++. For accessing the files, I'm using file mapping (see below) like any sane person. This is absolutely great for reading data, but a problem arises in actually editing the archive. File mapping does not allow resizing a file while it's being a...

How to know which files an application is trying to access?

How do I know which files and registry keys an application is trying to access? ...

VB6, File Doesn't Exist, How do I handle Gracefully?

Hi, I am testing an application that checks if a file exists across a network. In my testing, I am purposefully pulling the network plug so the file will not be found. The problem is this causes my app to go unresponsive for at least 15 seconds. I have used both the FileExists() and GetAttr() functions in VB6. Does anyone know how to...