You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下批量保留目录结构创建.nki文件快捷方式的方法

在Windows中批量创建.nki文件的快捷方式并保留原目录结构

可以通过PowerShell或批处理脚本一次性完成需求,以下是两种可行方案:

PowerShell 脚本方案(推荐)

Windows自带的PowerShell无需额外工具,直接用以下脚本实现:

# 替换为你的源目录和目标目录
$sourceDir = "C:\Example\SourceFolder"
$targetDir = "C:\Example\TargetFolder"

# 递归遍历所有.nki文件并创建对应快捷方式
Get-ChildItem -Path $sourceDir -Filter "*.nki" -Recurse | ForEach-Object {
    # 生成目标路径(保留原目录结构)
    $targetFilePath = $_.FullName.Replace($sourceDir, $targetDir)
    $targetFolder = Split-Path -Path $targetFilePath -Parent
    
    # 自动创建不存在的目标文件夹
    if (-not (Test-Path $targetFolder)) {
        New-Item -ItemType Directory -Path $targetFolder | Out-Null
    }
    
    # 创建指向原文件的快捷方式
    $shortcutPath = [System.IO.Path]::ChangeExtension($targetFilePath, ".lnk")
    $wshShell = New-Object -ComObject WScript.Shell
    $shortcut = $wshShell.CreateShortcut($shortcutPath)
    $shortcut.TargetPath = $_.FullName
    $shortcut.Save()
}

使用步骤:

  • 修改$sourceDir和$targetDir为实际的文件夹路径
  • 打开PowerShell(按下Win+X选Windows PowerShell)
  • 将脚本粘贴到窗口中,按回车执行

批处理脚本方案

如果习惯使用CMD批处理,可通过批处理+VBS脚本组合实现:

  1. 创建CreateShortcut.vbs文件,内容如下:
Set objWSHShell = CreateObject("WScript.Shell")
Set objShortcut = objWSHShell.CreateShortcut(WScript.Arguments(0))
objShortcut.TargetPath = WScript.Arguments(1)
objShortcut.Save
  1. 创建NKIShortcuts.bat批处理文件,内容:
@echo off
set "sourceDir=C:\Example\SourceFolder"
set "targetDir=C:\Example\TargetFolder"

for /r "%sourceDir%" %%f in (*.nki) do (
    set "relPath=%%f:%sourceDir%=%"
    md "%targetDir%\%relPath%\.." 2>nul
    cscript //nologo CreateShortcut.vbs "%targetDir%\%relPath:.nki=.lnk%" "%%f"
)

使用步骤:

  • 修改sourceDir和targetDir为实际路径
  • 将两个文件放在同一目录下,双击NKIShortcuts.bat执行

内容的提问来源于stack exchange,提问作者Barral39

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 16:33:31