Tag Archives: file names

List characters that are invalid in file and path names in C#

This example uses the following code to display characters that are invalid in file and path names. private void Form1_Load(object sender, EventArgs e) { string txt = “”; foreach (char ch in Path.GetInvalidFileNameChars()) { if (Char.IsWhiteSpace(ch) || Char.IsControl(ch)) txt += … Continue reading

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

Convert between long and short file names in C#

You can use the GetShortPathName API function to convert from long to short file names. The following code declares the API function. // Define GetShortPathName API function. [DllImport(“kernel32.dll”, CharSet = CharSet.Auto, SetLastError = true)] static extern uint GetShortPathName(string lpszLongPath, char[] … Continue reading

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

Combine and resolve relative paths in C#

Often it’s useful for a C# program to combine relative paths. For example, when you build a program in Visual Studio, the executable program runs in the bin\Debug subdirectory below the source code directory. If you want to manipulate a … Continue reading

Posted in files, system | Tagged , , , , , , , , , , , | 4 Comments

Test different methods that compare directories to see which files they have in common in C#

The example Compare directories to see which files they have in common in C# uses Directory.GetFiles to get the files in two directories. It sorts them and compares the two sorted lists to see which files are in the first … Continue reading

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

Compare directories to see which files they have in common in C#

This example compares directories to see which files they have in common and which files are only in one directory. When you click the Compare button, the following code executes. // Compare the files in each directory. private void btnCompare_Click(object … Continue reading

Posted in directories, files | Tagged , , , , , , , , , , , | 6 Comments