directoryinfo

DirectoryInfo.GetDirectories() and attributes

I am using DirectoryInfo.GetDirectories() recursively to find the all the sub-directories under a given path. How ever I want to exclude the System folders and there is no clear way for that. In FindFirstFile/FindNextFile things were clearer with the attributes. Thanks in advanced. ...

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

recording all the files in a large directory

Hi, I've got a number of directories with a large number of files in them (~10,000). I want to create a list of these files in my app, and have already threaded the io access so that the app doesn't freeze while they load. However if I exit the app before all files are loaded, the thread doesn't respond to the .Join() until the call t...

Is there an async version of DirectoryInfo.GetFiles / Directory.GetDirectories in dotNet?

Is there an asynchronous version of DirectoryInfo.GetFiles / Directory.GetDirectories in dotNet? I'd like to use them in an F# async block, and it'd be nice to have a version that can be called with AsyncCallbacks. Problem is I'm trying to suck in a bunch of directories, probably on SMB mounts over slow network connections, and I don...

How do you implement a IEqualityComparer<T> in VB.NET?

I have the following function that loops through a directory and checks for a specified folder and file: Private Function VerifyPath(ByVal root As String, ByVal folder As String, _ ByVal file As String) As Boolean Dim folders As New List(Of String), files As New List(Of String) Dim oDir As New IO.Di...

Find matched directories using a list of regular expressions

I have an IEnumerable<DirectoryInfo> that I want to filter down using an array of regular expressions to find the potential matches. I've been trying to join my directory and regex strings using linq, but can't seem to get it right. Here's what I'm trying to do... string[] regexStrings = ... // some regex match code here. // get all ...

C# DirectoryInfo.getFiles begining with

I've come across some strange behavior trying to get files that start with a certain string. Please would someone give a working example on this: I want to get all files in a directory that begin with a certain string, but also contain the xml extension. for example: apples_01.xml apples_02.xml pears_03.xml I want to be able t...

C#: How to logon to a share when using DirectoryInfo

If I want to instantiate a DirectoryInfo object with an UNC path DirectoryInfo myDI = new DirectoryInfo (@"\\server\share"); how can I pass a username / password that is required to access that share? Thanks ...

Can certain File.IO objects in .NET (like DirectoryInfo) keep a removable device referenced even after programm termination

I have written a program in .NET that recurses through all files of a source and destination directory and its subdirectories, compares lastwritetime and copies/deletes files to/from the destination directory based upon comparison result. When eg. the destination directory is a directory on a removable drive (usb), I can not remove the ...

DirectoryInfo, FileInfo and very long path

I try to work with DirectoryInfo, FileInfo with very long path. I try use \\?\c:\long path (i got illegal caracter with fileInfo and DirectoryInfo) I try use file://c:/long path (i got uri not supported) Can i use ~ in a path or something else. I read this post but i would like to use another way that call a API. Is it any other sol...

C# - How to use DirectorySecurity.SetOwner() ? I'm having troubles

I'm having troubles figuring out the SetOwner() method. In my case, i've created a user in Active Directory by code, then, I create a folder for the user, it all works ok, but I cannot set the newly created user as the owner of the folder. I'm not a c# guru, so I'm having troubles understanding the DirectorySecurity.SetOwner() function. ...

How do I compare one collection of files to another in c#?

I am just learning C# (have been fiddling with it for about 2 days now) and I've decided that, for leaning purposes, I will rebuild an old app I made in VB6 for syncing files (generally across a network). When I wrote the code in VB 6, it worked approximately like this: Create a Scripting.FileSystemObject Create directory objects for ...

Copying files to/from a "Portable Device"

I have run into a problem with a couple of the "Sync" applications I wanted to create. In both instances, I am trying to connect a Portable Device to my computer and access it using VB.NET. One application would pull the pictures in from my camera, rename them, and put them in folders according to their date taken. The other would place ...

.NET - Check if directory is accessible without exception handling

I need to go through various directories on the computer (via DirectoryInfo). Some of them aren't accessible, and UnauthorizedAccessException occurs. How can I check directory access without catching the exception? ...

Understanding a boolean on DirectoryInfo.Exists

Hi everyone, var fileOpen = new OpenFileDialog(); var clickedOk = fileOpen.ShowDialog(); if (!((bool) clickedOk)) return; var path = fileOpen.FileName; var diPath = new DirectoryInfo(path); var fiPath = new FileInfo(path); Debug.WriteLine(diPath.Exists); I am just wondering why diPath.Exists is false in this case? Since the user has...

how do you convert a directoryInfo file to string

Problem is that i cant convert to string Dim path As String = "..\..\..\Tier1 downloads\CourseVB\" If countNumberOfFolders > 0 Then 'if there is a folder then ' make a reference to a directory Dim di As New IO.DirectoryInfo(path) Dim diar1 As IO.DirectoryInfo() = di.GetDirectories() Dim dra As IO.DirectoryInfo '...

/clr option in c++

Can someone help me find a solution to the following error: "fatal error C1190: managed targeted code requires a '/clr' option" My configuration is .. Visual studio 2008 Windows 7 Here is the code (i got by using net resources) #using <mscorlib.dll> using namespace System; using namespace System::IO; int main() { // C...

Set NTFS Permissions with DirectorySecurity after created Active Dirctory Groups

I am a little confused about setting NTFS Permissions to a directory after I created Active Directory Groups (both programmatically). When I created the Active Directory Objects then I have to wait a few seconds to set the NTFS Permissions. If I have not this timeout then I get sometimes an error message that the identify (active directo...

Using DirectoryInfo in C#

If there a more efficient way to do the following: DirectoryInfo di = new DirectoryInfo(@"c:\"); newFileName = Path.Combine(di.FullName, "MyFile.Txt"); I realise that it’s only two lines of code, but given that I already have the directory, it feels like I should be able to do something like: newFileName = di.Combine(“MyFile.txt”); ...

Directory vs DirectoryInfo

Are they equavalent? Are they alternative? Is one of them depricated one other? Which one is working better in a ASP.NET web app. sepcially when I was to extract all files of a specific driectory recursively? Many Thanks in Advance ...