Z
Zolfaghar
Guest
I need some help with creating a list of urls in my favorites folder. I need to know if I need to open each file, which is of type .url and parse it to match the url and save it to a list<string> or is a there a better way to do it? That is, can I save the other information in the .url file? if I can, I like to do it. Are there types in C#, which I should use besides the string type? If there are types that make other tasks easier I like to know about it please.
Here is what I have so far:
string favorites = @"C:\Users\usr\Favorites";
if (File.Exists(favorites))
{
// This path is a file
ProcessFile(favorites);
}
else if (Directory.Exists(favorites))
{
// This path is a directory
ProcessDirectory(favorites);
}
else
{
Console.WriteLine("{0} is not a valid file or directory.", favorites);
}
}
// Process all files in the directory passed in, recurse on any directories
// that are found, and process the files they contain.
public static void ProcessDirectory(string targetDirectory)
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(targetDirectory);
foreach (string fileName in fileEntries)
ProcessFile(fileName);
// Recurse into subdirectories of this directory.
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach (string subdirectory in subdirectoryEntries)
ProcessDirectory(subdirectory);
}
// Insert logic for processing found files here.
public static void ProcessFile(string path)
{
Console.WriteLine("Processed file '{0}'.", path);
// Add the file to the list of internet shortcut files
}
private void button1_Click(object sender, RoutedEventArgs e)
{
textBox1.Text = string.Empty;
}
Continue reading...
Here is what I have so far:
string favorites = @"C:\Users\usr\Favorites";
if (File.Exists(favorites))
{
// This path is a file
ProcessFile(favorites);
}
else if (Directory.Exists(favorites))
{
// This path is a directory
ProcessDirectory(favorites);
}
else
{
Console.WriteLine("{0} is not a valid file or directory.", favorites);
}
}
// Process all files in the directory passed in, recurse on any directories
// that are found, and process the files they contain.
public static void ProcessDirectory(string targetDirectory)
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(targetDirectory);
foreach (string fileName in fileEntries)
ProcessFile(fileName);
// Recurse into subdirectories of this directory.
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach (string subdirectory in subdirectoryEntries)
ProcessDirectory(subdirectory);
}
// Insert logic for processing found files here.
public static void ProcessFile(string path)
{
Console.WriteLine("Processed file '{0}'.", path);
// Add the file to the list of internet shortcut files
}
private void button1_Click(object sender, RoutedEventArgs e)
{
textBox1.Text = string.Empty;
}
Continue reading...