-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathNCV.cs
More file actions
48 lines (40 loc) · 1.66 KB
/
NCV.cs
File metadata and controls
48 lines (40 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.IO;
namespace NCV
{
class Program
{
static void Main()
{
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
// Get all files (including shortcuts) from the desktop
string[] filesOnDesktop = Directory.GetFiles(desktopPath, "*.*", SearchOption.TopDirectoryOnly);
// Collect files and shortcuts information into a StringBuilder
var fileInformation = new System.Text.StringBuilder();
foreach (string file in filesOnDesktop)
{
string fileName = Path.GetFileName(file);
fileInformation.AppendLine(fileName);
}
// You can also filter out specific file types or extensions if needed
// For example, to get only shortcuts (.lnk files)
string[] shortcutsOnDesktop = Directory.GetFiles(desktopPath, "*.lnk", SearchOption.TopDirectoryOnly);
foreach (string shortcut in shortcutsOnDesktop)
{
string shortcutName = Path.GetFileName(shortcut);
fileInformation.AppendLine(shortcutName);
}
// Save the collected information to a file
string outputPath = Path.Combine(desktopPath, "DesktopFilesInfo.txt");
try
{
File.WriteAllText(outputPath, fileInformation.ToString());
//Console.WriteLine($"File information saved to: {outputPath}");
}
catch (Exception ex)
{
Console.WriteLine($"Error saving file information: {ex.Message}");
}
}
}
}