powershell - Powershell vs GUI shortcuts
问题描述
I have a file named new.txt. Using GUI I can create a shortcut, for example, "new.lnk". When I click on "new.lnk" file, Notepad is opened with the contents of "new.txt" file. When I create the shortcut using PowerShell
NEW-ITEM -TYPE SYMBOLICLINK -TARGET "NEW.TXT" "NEW.LNK"
I can see the contents of the file using
CAT "NEW.LNK"
but the shortcut file is not working in the GUI: it does nothing.
I expect to see the contents in Notepad editor. The properties of the file created using GUI and PowerShell are the same, except for "Start in" information: blank when the short cut is created using PowerShell and with the path file directory when using GUI.
解决方案
符号链接(symlink)不等同于 Windows 快捷方式。在文件系统级别创建符号链接 - 它表示“这是一个具有此类文件名的文件,但内容实际上在另一个文件中”。它的大小是 0 字节,因为它只是指向其他文件。将文件命名为“new-linked.txt”而不是“new.lnk”会更合适。
快捷方式“.lnk”是由 Windows shell 解释的单独文件。它包含目标文件的路径(以及其他附加属性)。如果您从 UI 创建快捷方式然后尝试cat my.lnk
,您将看到快捷方式文件本身的内容,而不是目标文件。
要从 Powershell 创建 Windows 快捷方式,请参阅如何使用 PowerShell 创建快捷方式。
推荐阅读
- postgresql - 未处理的拒绝 SequelizeForeignKeyConstraintError:在表上插入或更新
- angular - 如何在 Angular 6 中实现内容显示更多和更少显示
- email - 发送电子邮件副本(状态)prestashop 1.7.2
- rest - 工厂方法设计模式的RESTful实现
- jquery - 获取选定的选项元素
- php - 来自数据库的php循环
- ruby - Ruby 类中的可选哈希选项
- python - 比较运算符如何与 a[i:] < b[i:] 一起使用?
- javascript - 在 Web 应用程序上导航
- vba - 从 VBA 控制 Internet Explorer