files

os.walk without digging into directories below

How do i limit os.walk to only return files in the directory i provide it? def _dir_list(self, dir_name, whitelist): outputList = [] for root, dirs, files in os.walk(dir_name): for f in files: if os.path.splitext(f)[1] in whitelist: outputList.append(os.path.join(root, f)) else: ...

Winforms csv file generation, want to generate file then ask user to save it or open it

Hi, When a user clicks on a button on the winforms application, I will generate a CSV file. I then want to ask the user to either save the file to disk OR open the file. How can I do that? Note: I am just generating the file in memory, not writing it to disk until the user selects the path to save it to. ...

Tracing which process that has opened a particular file

Hi, From kernel mode in Windows I'm able to intercept and monitor virtually all actions performed on a particular disk. When a file is opened for any purpose I get an event. Now I want to trace which application that opened it. I think this should be possible but don't know how. I'm using the standard file management functions in Wind...

What's the best way to return a random line in a text file using C?

What's the best way to return a random line in a text file using C? It has to use the standard I/O library (<stdio.h>) because it's for Nintendo DS homebrew. Clarifications: Using a header in the file to store the number of lines won't work for what I want to do. I want it to be as random as possible (the best being if each line has a...

How to backup project folders to local desktop if path more than 255 characters?

For e.g. if i am storing some files on a network server which is under many hiearchial folders. Then i want to do backup. But i always encounter issue because the file path is more than 255? How can i resolve this issue or work around it? ...

SVN: How do I maintain my local config.blah file?

Hi! On the SVN server, there is a file called config.conf. I have a local version called the same thing (in the same place). How can I make sure that my local config does not get overwritten, nor checked in? While I'm here, is the answer different for a directory? I'm using Tortoise SVN, but command line answers are cool. Thanks! [...

Best way to implement file access in C#

Scenario - I need to access an HTML template to generate a e-mail from my Business Logic Layer. It is a class library contains a sub folder that contains the file. When I tried the following code in a unit test: string FilePath = string.Format(@"{0}\templates\MyFile.htm", Environment.CurrentDirectory); string FilePath1 = string.Format...

Is there a standard way to do findfirst, findnext with gcc on linux using stl?

I can't seem to find the _findfirst / findfirst, _findnext / findnext API on gcc for Linux, and would actually rather use the Standard Template Library (STL) for that if it is included there. Does anyone know what API there is available for listing files in a directory under Linux for C++ (gcc)? ...

How to get file creation & modification date/times in Python?

I have a script that needs to do some stuff based on file creation & modification dates but has to run on Linux & Windows. What's the best cross-platform way to get file creation & modification date/times in Python? ...

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...

How do I programmatically get a list of locked files under a folder structure?

Following up from this question: How can I unlock a file that is locked by a process in .NET, how do I programmatically get a list of files that are locked in a particular folder and its subfolders? I'm using Windows 2003, .NET 3.5, C# 3.0. Update: some background... basically we're archiving closed websites on a shared server. After d...

CRC checks for files

I'm working with a small FAT16 filesystem, and I want to generate CRC values for indidual XML files which store configuration information. In case the data changes or is corrupted, I want to be able to check the CRC to determine that the file is still in it's original state. The question is, how do I put the CRC value into the file, wit...

Create file with given size in Java

Is there an efficient way to create a file with a given size in Java? In C it can be done like in that answer. Most people would just write n dummy bytes into the file, but there must be a faster way. I'm thinking of ftruncate and also of Sparse files… ...

Java File Cursor

Hi, Is there some library for using some sort of cursor over a file? I have to read big files, but can't afford to read them all at once into memory. I'm aware of java.nio, but I want to use a higher level API. A little backgrond: I have a tool written in GWT that analyzes submitted xml documents and then pretty prints the xml, among o...

Reading and Parsing Files in .NET - Performance For Hire

Hi, I want the most performat way to read and parse a file. Is it possible to read a file in .NET, but not load the entire file into memory? i.e. just load the file line by line as I parse the content of each row? Does XmlTextReader load the entire file into memory or does it stream the file into memory as it reads the file? ...

Natural Sort Order in C#

Anyone have a good resource or provide a sample of a natural order sort in C# for an FileInfo array? I am implementing the IComparer interface in my sorts. ...

What are these stray zero-byte files extracted from tarball? (OSX)

I'm extracting a folder from a tarball, and I see these zero-byte files showing up in the result (where they are not in the source.) Setup (all on OS X): On machine one, I have a directory /My/Stuff/Goes/Here/ containing several hundred files. I build it like this tar -cZf mystuff.tgz /My/Stuff/Goes/Here/ On machine two, I scp the t...

Are windows file creation timestamps reliable?

I have a program that uses save files. It needs to load the newest save file, but fall back on the next newest if that one is unavailable or corrupted. Can I use the windows file creation timestamp to tell the order of when they were created, or is this unreliable? I am asking because the "changed" timestamps seem unreliable. I can embed...

Header files in dev-C++

I'm trying to add an header file to dev-C++ but when I compile it it doesn't work. Here are my exact steps (for my example, I'm trying to get mysql.h to work): copy "mysql.h" into c:\dev-c++\includes check that in dev-C++ tools > compiler options > directories > c includes and c++ includes have the path to "c:\dev-c++\includes" include...

Quickly create a large file on a linux system?

How can I quickly create a large file on a Linux (RHEL) system? dd will do the job, but reading from /dev/zeo and writing to the drive can take a long time when you need a file several hundreds of GB in size for testing... if you need to do that repeatedly the time really adds up. I don't care about the contents of the file, I just wan...