Tag Archives: directories

Initialize a TreeView control to display a directory hierarchy in C#

This example adds the following LoadFromDirectory extension method to the TreeView control. // Initialize the TreeView from a directory, // its subdirectories, and their files. public static void LoadFromDirectory(this TreeView trv, string directory, int folder_img, int file_img) { DirectoryInfo dir_info … Continue reading

Posted in controls, directories, extension methods, files, user interface | Tagged , , , , , , , , , , , , , | Leave a comment

Find files in the startup directory in C#

In some programs you may want to find files that were installed with the program. One way to do that is to put the files in the program’s installation directory. Open the Project menu, select Add Existing Item, find the … Continue reading

Posted in directories, files | Tagged , , , , , , , , , , , , | Leave a comment

List the locations of special folders in C#

The System.Environment class’s SpecialFolders enumeration lists special folders such as System, Cookies, Desktop, and so forth. The class’s GetFolderPath method returns the full path for one of the special folders values. This program uses the following code to enumerate the … Continue reading

Posted in directories, files, system | Tagged , , , , , , , , , , , | 2 Comments

Create a directory and intermediate directories in C#

The System.IO.Directory class’s CreateDirectory method creates a directory. If the directory’s path includes missing intermediate directories, it creates them, too. For example, if C:\DirA is empty and you use CreateDirectory to create C:\DirA\DirB\DirC, then the method automatically creates DirB as … Continue reading

Posted in directories | Tagged , , , , , , , , , | 1 Comment

Let the user select a folder in C#

This example demonstrates two handy techniques. First, it lets you select a folder. When you click the program’s ellipsis button, the following code displays a FolderBrowserDialog. This lets the user pick a directory instead of needing to type it in. … Continue reading

Posted in directories, files, system | Tagged , , , , , , , , , , , , | Leave a comment

Number files in a directory in C#

I recently went on a trip where I took almost a thousand pictures. My phone (which has a pretty good camera) gives the pictures file names such as WP_20151106_22_04_47_Pro.jpg. I wanted an easy way to number files so they have … Continue reading

Posted in directories, files, system | Tagged , , , , , , , , , | Leave a comment

List Dropbox directories and files in C#

Dropbox is a file sharing service. The free Basic version lets you easily share up to 2 GB of files across the internet. The $9.99/month Pro version gives you up to 1 TB and the $15.00/month Business version gives you … Continue reading

Posted in directories, files, system, tools | Tagged , , , , , , , , , , , , , , | Leave a comment

Manage the recycle bin (wastebasket) in C#

You can use API functions to manage the recycle bin, but some operations are much easier if you use the Microsoft.VisualBasic library. You can use the API if you like, but I’d rather do things the easiest way possible to … Continue reading

Posted in files, system | Tagged , , , , , , , , , , , , , , , , | Leave a comment

Find, open, and replace text in files in C#

The example Find files and replace text in them in C# shows how you can find and replace text in files. This example modifies that one to let you open the files you find by double clicking on them in … Continue reading

Posted in directories, files, tools | Tagged , , , , , , , , , , , , , | Leave a comment

Find files and replace text in them in C#

This program lets you recursively find files in a directory hierarchy that match one or more patterns. You can then replace text in those files with new text. Both the Find and Find & Replace buttons call the SearchForFiles method. … Continue reading

Posted in directories, files, tools | Tagged , , , , , , , , , , , | 1 Comment