file-io

cobol Open-IO: create file if it doesn't exist

Does anyone have an idea how you can catch the exception that cobol throws if you try to open an IO file if it doesn't exist, and then create a new file? ...

How do I rename (not move) a file in JDK7?

Hello! I'm a bit confused with all these new File I/O classes in JDK7. Let's say, I have a Path and want to rename the file, it represents. How do I specify the new name, when again a Path is expected? Path p = /* path to /home/me/file123 */; Path name = p.getName(); /* gives me file123 */ name.moveTo(/* what now? */); /* how to renam...

Check if folder is in use in C#

Consider a network folder: \\desiis\c$\Company\B2b\Monitor On that machine, any process that tries to delete the directory Monitor receives an error because a user on the LAN has that directory open (likely with Windows Explorer). Can I detect, via C# and .NET framework, if any user (and which user) has a particular directory open/in ...

Searching Subdirectories in C#

I have a list of file names, and I want to search a directory and all its subdirectories. These directories contain about 200,000 files each. My code finds the the file but it takes about 20 minutes per file. Can someone suggest a better method? Code Snippet String[] file_names = File.ReadAllLines(@"C:\file.txt"); foreach(string fil...

Java: How to "trim" a byte array?

So I have some code that reads a certain amount of bytes from a file and returns the resulting byte array (this is basically used for chunking up files to send over the network as (eventually) base64-encoded ascii text). It works fine, except that when the last chunk of the file is generated, it isnt a full chunk. Therefore, the resulti...

Further questions on Searching subdirectories in C#

I asked a question recently on searching directories in C#. Program Logic List all the directories in a string, or multiple strings. Try to copy the file out using the string. If it fails, proceed to the next string, If it succeeds in finding the file: copy skip to next entry in text file End Result If it finds it on the ...

Reading in files that contain specific characters in C#

I have a text file named C:/test.txt: 1 2 3 4 5 6 I want to read every number in this file using StreamReader. How can I do that? ...

Reading the same file multiple times in Python

Hello, I need to download a zip archive of text files, dispatch each text file in the archive to other handlers for processing, and finally write the unzipped text file to disk. I have the following code. It uses multiple open/close on the same file, which does not seem elegant. How do I make it more elegant and efficient? zipped = ur...

How to permanently delete file so that it becomes unrecoverable?

If I want my application (written in .NET) to delete a file such that it can not be recovered by disk recovery tool. What are my options? One that I can think of is that I open it up in write mode, overwrite all of it with some random data and it would make the file unrecoverable. Is there any other way? ...

count number of files with a given extension in a directory - C++?

Hi there, Is it possible in c++ to count the number of files with a given extension in a directory? I'm writing a program where it would be nice to do something like this (pseudo-code): if (file_extension == ".foo") num_files++; for (int i = 0; i < num_files; i++) // do something Obviously, this program is much more complex,...

C/C++ Copy file with automatic recursive folder/directory creation

In Win32 API, there is CopyFile that literally copies a file. However, this API doesn't create folders. For example, I'd like to copy C:\Data\output.txt to D:\Temp\Data\output.txt. But, the target folders, D:\Temp and D:\Temp\Data', do not exist. In this case, this API just fails. Is there a handy API that can automatically and recursiv...

C# Directory listing massive directory

Here is the scenario. I have a directory with 2+ million files. The code I have below writes out all the files in about 90 minutes. Does anybody have a way to speed it up or make this code more efficent? I'd also like to only write out the file names in the listing. string lines = (listBox1.Items.ToString()); string source...

Visual Basic program not releasing resource

I have a program written in VB.NET which stops a service that uses file x, modifies x, and restarts the service. I have modified my code for testing so that it just reads in the file as a string and immediately writes it back out. Shell("net stop " & SERVICE_NAME, , True) Dim myReader As System.IO.StreamReader myReader = My.Computer.F...

Create a File in a Biztalk message inside a orchestration

Hi! I'm having some trouble sending a file by ftp from my BizTalk 2006RC. The part the i struggle is to create a real file named "OPA0037" with only one line "OPA0037;TEST;;;" that it after the ftp part isn't a problem i juste don't see how to create a file from a message... It can only be in the orchestration. any help any idea is...

Win32 IO Performance Problem

Recently I ran into a "fun" problem with the Microsoft implementation of the CRTL. tmpfile places temp files in the root directory and completely ignores the temp file directory. This has issues with users who do not have privileges to the root directory (say, on our cluster). Moreover, using _tempnam would require the application to rem...

Can fscanf() read whitespace?

I've already got some code to read a text file using fscanf(), and now I need it modified so that fields that were previously whitespace-free need to allow whitespace. The text file is basically in the form of: title: DATA title: DATA etc... which is basically parsed using fgets(inputLine, 512, inputFile); sscanf(inputLine, ...

fclose return value check

Hi All, Is it required to check the return value of fclose? If we have successfully opened a file, what are the chances that it may fail to close? Thanks! Regards, Jay ...

c - get file into array of chars

hi i have the following code below, where i try to get all the lines of a file into an array... for example if in file data.txt i have the following: first line second line then in below code i want to get in data array the following: data[0] = "first line"; data[1] = "second line" My first question: Currently I am getting "Segmentat...

How to write a HEX string into a file as HEX using REXX..

I have a string 'RAJA' which should be written into a file as HEX data. Here are sample codes which help me to describe the issue. Case(a) name = 'RAJA' name = C2X(name) /* Hex value = '52414A41' */ QUEUE name. Output to the file: 52414A41 But if we use HEX data directly to write into file it's working fine Case(b) name = '52414A...

Formatted Input in Python

I have a peculiar problem. I need to read (from a txt file) using python only those substrings that are present at predefined range of offsets. Let's say 5-8 and 12-16. For example, if a line in the file is something like: abcdefghi akdhflskdhfhglskdjfhghsldk then I would like to read the two words - "efgh" and "kdhfl". Because, in t...