C# 使用C通过targetpath删除/修改快捷方式#
我们有用户将桌面上的快捷方式文件重命名为我们的应用程序。如果应用程序的图标更改,基于targetpath删除/修改快捷方式的最佳方式是什么?换句话说,我很难找到文件名,因为它一直在更改。要删除文件,请使用方法 要修改文件,可以使用方法 以下评论后更新: 请使用ShellClass创建或修改快捷方式,您也将 需要使用从桌面获取特殊目录 Environment.SpecialFolder.DesktopDirectory 在这里可以找到一个非常好的逐步演示示例C# 使用C通过targetpath删除/修改快捷方式#,c#,shortcut,C#,Shortcut,我们有用户将桌面上的快捷方式文件重命名为我们的应用程序。如果应用程序的图标更改,基于targetpath删除/修改快捷方式的最佳方式是什么?换句话说,我很难找到文件名,因为它一直在更改。要删除文件,请使用方法 要修改文件,可以使用方法 以下评论后更新: 请使用ShellClass创建或修改快捷方式,您也将 需要使用从桌面获取特殊目录 Environment.SpecialFolder.DesktopDirectory 在这里可以找到一个非常好的逐步演示示例 重命名快捷方式不会修改目标路径,但是,
重命名快捷方式不会修改目标路径,但是,我知道在c#中使用快捷方式的最佳方法是使用。您应该使用类: 侦听文件系统更改通知,并在 目录或目录中的文件发生更改 实际上,您可以利用
FileSystemWatcher.Changed
,FileSystemWatcher.Created
,FileSystemWatcher.rename
,FileSystemWatcher.Deleted
事件来保持对文件的控制
以下是MSDN的一个示例:
public static void Main()
{
// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "mypath";
/* Watch for changes in LastAccess and LastWrite times, and
the renaming of files or directories. */
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files.
watcher.Filter = "*.txt";
// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
// Begin watching.
watcher.EnableRaisingEvents = true;
// Wait for the user to quit the program.
Console.WriteLine("Press \'q\' to quit the sample.");
while(Console.Read()!='q');
}
// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is changed, created, or deleted.
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
}
private static void OnRenamed(object source, RenamedEventArgs e)
{
// Specify what is done when a file is renamed.
Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
}
你明白OP在问什么吗?@RobertHarvey&user766595我确实知道他的意思,但这里的问题是OP在谈论文件,而不是用C代码修改文件。如果应用程序没有启动,这会处理名称更改吗?是的,但显然你应该启动处理文件的应用程序。