file-io

How to delete the first and last lines from a text file in visual basic

I've seen posts on deleting the lines from a text file that are specified as a function parameter, but I only need to delete the first and last lines from the file. I'm still a newbie when it comes to working in files, but it seems that it should be simple to delete the first line... Just delete all text from BOF to the first CrLf chara...

jump into file line c#

how can i jump into some line in my file, e.g line 300 in c:\text.txt? ...

C# Problem with opened files

Is there a way to close a file in C#? if(File.Exists(TEMP_FILENAME)) File.Delete(TEMP_FILENAME); The above code complains that file is already used by another process. Is there a way to check the open file handles in VS 2008? ...

Is there a faster way than this to find all the files in a directory and all sub directories?

I'm writing a program that needs to search a directory and all its sub directories for files that have a certain extension. This is going to be used both on a local, and a network drive, so performance is a bit of an issue. Here's the recursive method I'm using now: private void GetFileList(string fileSearchPattern, string rootFold...

Download all the links from any page

Hi, I want to develop an asp.net page through which I can specify the URL of any page which contains links of many files & directories. I want to download them all. Similar to DownThemAll plugin of FireFox. i.e. "MyPage.htm" file contains many links to files/directories located on the same server. now I want to write a function which...

Reading from a file in C++

I'm trying to write a recursive function that does some formatting within a file I open for a class assignment. This is what I've written so far: const char * const FILENAME = "test.rtf"; void OpenFile(const char *fileName, ifstream &inFile) { inFile.open(FILENAME, ios_base::in); if (!inFile.is_open()) { cerr << "Could...

Occasional MySQL query Error in PHP

I have a php file that has to be loaded as a web page. This page is 17Kb in size. It has a php mysql query script inside. the problem now, sometimes my mysql_query() lines gives an error. When being refreshed, it works again. It just have an error sometimes on that same line. I check the query string and it was okay, for if that was the...

Create file without opening/locking it?

Hi, Does anyone know of a way to (reasonably simple) create a file without actually opening/locking it? In File class, the methods for file creation always return a FileStream. What I want to do is to create a file, rename it (with File.Move) and then use it. Now I have to: Create it Close Rename Reopen for use ...

Is there a way to retrieve the last character of a file without reading line by line?

I need to retrieve the last character of a file. It may be a line break, or one of many special characters. Can I retrieve this character without parsing through the entire file? Or is there a way that I can read an entire file into a string without worry about line breaks? I will essentially need to split the contents of the file, b...

How to identify whether folder is opened?

In my application I'm trying to rename the folder, but if the folder is opened in Windows Explorer I get an IOException. How can I identify whether folder is opened in Windows Explorer in C#? ...

How can we find the number of blocks occupied by a file from userspace

How can we find the number of blocks occupied by a file from userspace ? Is there a command to do so or we need to access the inode structure and then fetch the information. I have searched a lot on the internet but could not find a valid answer. Can you please let me know Thanks. ...

How to erase existing text in a file

I'm working on an assignment for school, and am trying something beyond for extra credit. The program is to demonstrate the efficiency differences between a linear & binary search for a given array size of integers. I have a loop set up that creates an int[size] array, searches for a random number, then creates a new array of int[size*...

Is there a widespread C library for reading name/value pairs from a file?

My program is reading a text file containing various lines of text for a settings file. Some of the lines could get very large. Currently the buffer size is 4096 chars. It is possible that some lines could exceed this, whether through maliciousness or due to various factors operating within the program. The current routines were rather ...

C#-fu - finding top-used words in a functional style

This little program finds the top ten most used words in a file. How would you, or could you, optimize this to process the file via line-by-line streaming, but keep it in the functional style it is now? static void Main(string[] args) { string path = @"C:\tools\copying.txt"; File.ReadAllText(path) .S...

Fast cross platform algorithm for reading/writing file in C++

I want to pose a seemingly simple question that i can't find the answer nowhere. Is there a FAST modern algorithm for file input and/or output that can be compiled with all standard compliant C++ compilers and works for all operating systems without the requirement of external libraries ? i have found that the fastest way is to use mem...

How can I get this File Writing code to work with Unicode (Delphi)

I had some code before I moved to Unicode and Delphi 2009 that appended some text to a log file a line at a time: procedure AppendToLogFile(S: string); // this function adds our log line to our shared log file // Doing it this way allows Wordpad to open it at the same time. var F, C1 : dword; begin if LogFileName <> '' then begin ...

Does it consume CPU when reading a large file

Suppose I want to do following opeartions on my 2-core machine: Read a very large file Compute Does the file reading operation need to consume 1 core? Previously I just create 2 threads, one to read file and one to compute? Should I create an additional thread to do compute? Thanks. Edit Thanks guys, yea, we should always conside...

Unable to delete a file after reading it.

I'm serving a file from the file system dynamically with a jsp Here's my code: <%@ page import="java.io.*,java.util.*" InputStream in = null; OutputStream responseOut = null; File file = new File(request.getAttribute("fileToServe")); try{ in = new FileInputStream(file); responseOut = response.getOutpu...

Should a class or method which processes a file close the file as a side effect?

I'm wondering which is the more 'Pythonic' / better way to write methods which process files. Should the method which processes the file close that file as a side effect? Should the concept of the data being a 'file' be completely abstracted from the method which is processing the data, meaning it should expect some 'stream' but not nece...

ZipPackage interaction with a shortcut

I have a folder structure containing a number of documents, as well as a shortcut link to another file in the folder structure. (essentially the file structure maps like a graph). If I zip up these files in Windows, the shortcut will point to the right file when the archive is uncompressed somewhere else. Now, I want to be able to do ...