system.io

Can you call Directory.GetFiles() with multiple filters?

I am trying to use the Directory.GetFiles() method to retrieve a list of files of multiple types, such as mp3's and jpg's. I have tried both of the following with no luck: Directory.GetFiles("C:\\path", "*.mp3|*.jpg", SearchOption.AllDirectories); Directory.GetFiles("C:\\path", "*.mp3;*.jpg", SearchOption.AllDirectories); Is there a ...

File.Move not working properly for UNC paths

I'm attempting to use File.Move to move a file from one UNC location to another. This blows up if the UNC path for the destination happens to be the local machine (error: Access to the path is denied). Example File.Move(@"\someServer\path\file.txt", @"\blah2\somewhere\file.txt"). This assumes there's a network share out there somewher...

Long to short pathnames without p/invoke

Does anyone know how to convert long to short pathnames in .net 3.5 without p/invoke? I can do it with p/invoke if I have to, but I'd rather not. ...

What is the best method to find the newest last modified time of a folder of files?

I have a folder with subfolders of files. I would like to get the newest filename by modified time. Is there a more efficient way of finding this short of looping through each folder and file to find it? ...

System.IO.Directory.GetFiles returns different result than Windows XP Search Companion

Hi, I am using this statement to find all files recursively: fileNames = System.IO.Directory.GetFiles(path, "*.*", System.IO.SearchOption.AllDirectories); The total number of files that are found is sgnificantly lower than wehen using Windows XP Search Companion. This is not caused by hidden files, I checked that. It looks like s...

Recursive File Search in .net

Hi, I need to search a drive (C:, D: etc) for a partuicular file type (extension like .xml, .csv, .xls). How do I preform a recursive search to loop all directories and inner directories and return the full path of where the file(s) are? or where can I get information on this? VB.NET or C# Thanks Edit ~ I am running into some errors ...

c# - Function to replicate the folder structure in the file path.

I need a simple function which will take a FileInfo and a destination_directory_name as input, get the file path from the fileinfo and replicate it in the destination_directory_name passed as the second parameter. for ex. filepath is "d:\recordings\location1\client1\job1\file1.ext the function should create the directories in the destin...

Calling Directory.Exists("\\SERVER\SHARE\") in Setup Project

I have a .NET Setup Project to which I've added a custom installer action. During the setup process, the user has to provide a path (which often is a UNC path) to a share on their file server. I attempt to do some validation before proceeding to make sure the directory exists, as such: if (!Directory.Exists(serverDirectory)) { th...

output a .txt file from a StreamWriter without writing to disk?

Is there any way to take a StreamWriter and output the file (in this case a .txt file) to the user with the option to open/save without actually writing the file to disk? If it is not saved it will basically go away. I am looking for the same functionality of HttpContext.Current.Response.TransmitFile(file); but without having to sav...

Derived System.Data classes

I would like to utilize classes that inherit the System.Data name space. Specifically, I would like to have classes CarColumn, CarTable, and CarSet derived from DataColumn, DataTable, and Dataset respectively. I would like to be able to add additional properities to each class. As an example this is how I would like to reference items...

Reset position of StringReader

StringReader rdr = new StringReader(finalXML); //Reader is a property which returns XmlTextReader Reader = new XmlTextReader(rdr); XmlReader reader = XmlReader.Create(rdr, settings); The last line throws an exception as the root element is missing because it is at the end of the stream. _pos value shows that it has read all the c...

How do I check if a filename matches a wildcard pattern

I've got a wildcard pattern, perhaps "*.txt" or "POS??.dat". I also have list of filenames in memory that I need to compare to that pattern. How would I do that, keeping in mind I need exactly the same semantics that IO.DirectoryInfo.GetFiles(pattern) uses. EDIT: Blindly translating this into a regex will NOT work. ...

Copy Folders in C# using System.IO

Hi I need to Copy folder C:\FromFolder to C:\ToFolder Below is code that will CUT my FromFolder and then will create my ToFolder. So my FromFolder will be gone and all the items will be in the newly created folder called ToFolder System.IO.Directory.Move(@"C:\FromFolder ", @"C:\ToFolder"); But i just want to Copy the files in FromFo...

VB.Net File.Copy/File.Move with different credentials

Ideally I'd like to be able to copy/move between an accessible folder on my local drive and a network share that I don't have permission to access (but the application would). I am using impersonation to give me access to the files in the network share but using System.IO File.Move or File.Copy forces me to use the same credentials for ...

Detecting a file opening

Is it possible in the Windows environment to detect if a file is being opened with with .NET I would like to place a handler on the file system to detect if a file or any file is being opened, is this possible? ...

Handler for file names

When windows is displaying the files through Window Explorer I need to have the ability to change the icon of the file type before it is displayed. I have seen application like SubVersion and Carbonite, change the icons depending on their status, but how do you do this? ...

IO 101: Which are the main differences between TextWriter, FileStream and StreamWriter?

Let me first apologize if this question could sound perhaps sort of amateurish for the seasoned programmers among you, the thing is I've been having many arguments about this at work so I really want to get this straight and that's basically why I'm relying on the stackoverflow community to get this settled once and for all :) So, on th...

Why Can't I do String.Replace() on a IO.File.ReadAllText() string?

I am using System.IO.FIle.ReadAllText() to get the contents of some template files that I created for email content. Then I want to do a Replace on certain tokens within the files so I can add dynamic content to the template. Here is the code I have, it seems to me like it should work just fine... Dim confirmUrl As String = Request.App...

How do I get a directory size (files in the directory) in C#?

I want to be able to get the size of one of the local directories using C#. I'm trying to avoid the following (pseudo like code), although in the worst case scenario I will have to settle for this: int GetSize(Directory) { int Size = 0; foreach ( File in Directory ) { FileInfo fInfo of File; ...

Read file that is used by another process.

Hi everyone. Is there ability to read file that is used by another process? Thanks. ...