AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1679216
Accepted
Cave Johnson
Cave Johnson
Asked: 2021-10-01 22:00:39 +0800 CST2021-10-01 22:00:39 +0800 CST 2021-10-01 22:00:39 +0800 CST

将文件夹移动到指向另一个驱动器的符号链接时出现“访问被拒绝”

  • 772

我有一个名为 D 的驱动器和一个名为 E 的驱动器。我使用 mkdir 命令在驱动器 D 中创建了一个名为“test”的文件夹,并在驱动器 E 中创建了一个名为“destination”的文件夹。然后在 DI 中使用以下命令创建了一个符号链接:

mklink /D D:\source E:\destination

现在,当我尝试使用命令将名为“test”的文件夹从 D 移动到 D:\source 时move D:\test D:\source,我收到一条错误消息,只是说“访问被拒绝”。如果我尝试使用命令移动名为“test.txt”的文件move D:\test.txt D:\source,则不会出现错误,并且该文件已成功移动到 E:\destination。

我也尝试在 powershell 中使用该命令执行此操作mv D:\test\ D:\source\并得到相同的结果,但我收到一条更长的错误消息,内容如下:

mv : Access to the path 'D:\test\' is denied.
At line:1 char:1
+ mv D:\test\ D:\source\
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (D:\test\:DirectoryInfo) [Move-Item], IOException
    + FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand

有趣的是,我刚刚注意到将测试文件夹直接移动到目标文件夹move D:\test E:\destination也会触发“访问被拒绝”错误。所以我的问题可能与符号链接无关。但是,在 powershell 中移动文件夹move D:\test E:\destination可以正常工作(而当它是符号链接时它会失败)。这很奇怪。

为什么我会收到此访问被拒绝错误,为什么如果我尝试移动文件夹而不是文件,它只会返回错误?另外为什么直接移动文件夹在cmd中失败但在powershell中成功?我能做些什么来规避这个错误吗?

注意:我以管理员身份尝试了所有命令。

这是目标文件夹属性的安全选项卡:

目标文件夹属性的安全选项卡

这是测试文件夹属性的安全选项卡:

测试文件夹属性的安全选项卡

powershell command-line
  • 1 1 个回答
  • 1763 Views

1 个回答

  • Voted
  1. Best Answer
    tukan
    2021-10-07T00:22:42+08:002021-10-07T00:22:42+08:00

    一个让我思考的有趣问题。@harrymc 是对的。这与权限无关。

    您使用moveatcmd.exe或PowerShell

    move命令 at与fromcmd.exe是不同的程序。 at实际上只是 while 的别名,它是一个内部命令。请参阅下面的注释了解不同之处!movePowerShellMovePowerShellMove-Itemmovecmd.exe

    问题

    对于符号链接或交汇点,此问题将相同(有关差异的更多信息,请参见directory-junction-vs-directory-symbolic-link)。

    问题是move( cmd.exe) 和Move-Item( PowerShell) 的内部函数无法处理驱动器音量的变化。本质上,它与PowerShell 7.2的回归 Move-Item相同。问题的核心是该功能MoveTo()无法处理驱动器音量变化(在符号链接上),并且必须有一个后备CopyAndDelete()功能。

    解决方案

    @cmd.exe

    的解决方案cmd.exe是使用robocopy( c:\Windows\System32\Robocopy.exe)。Windows 10 的robocopy折旧也可以使用,但将来可能会被删除,因此示例仅供参考。xcopyxcopyrobocopy

    一个例子:

    要将目录移动到符号链接目录:

    一个)robocopy d:\test d:\destination /E /MOVE

    /E : Copy Subfolders, including Empty Subfolders.

    /MOVE : Move files and dirs (delete from source after copying).

    请注意一个功能:如果目录d:\test为空,它将不会被移动,但会被删除。

    b)robocopy d:\test d:\destination /S /MOV

    /S : Copy Subfolders. /MOV : MOVe files (delete from source after copying).

    复制非空子文件夹并仅在复制后删除文件。

    @电源外壳

    您也可以在robocopy.exe此处使用,但如果您想为所有 PowerShell 版本本地执行此操作,则必须使用(类似于上面的“修复”,当符号链接上的驱动器卷更改copy&delete回退时)。

    这是一行:

    Copy-Item -Path d:\test -Destination d:\destination; Delete-Item -Path d:\test

    注意:如果您有问题,Delete-Item可以尝试使用-Force开关。

    我使用PowerShell 5.1.18362.1801的移动目录回归可能会在以后的版本中修复。

    笔记

    PowerShell移动

    NAME
        Move-Item
    
    SYNTAX
        Move-Item [-Path] <string[]> [[-Destination] <string>] [-Force] [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>
        ] [-PassThru] [-Credential <pscredential>] [-WhatIf] [-Confirm] [-UseTransaction]  [<CommonParameters>]
    
        Move-Item [[-Destination] <string>] -LiteralPath <string[]> [-Force] [-Filter <string>] [-Include <string[]>] [-Exclude <stri
        ng[]>] [-PassThru] [-Credential <pscredential>] [-WhatIf] [-Confirm] [-UseTransaction]  [<CommonParameters>]
    
    
    ALIASES
        mi
        mv
        move
    
    
    REMARKS
        Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
            -- To download and install Help files for the module that includes this cmdlet, use Update-Help.
            -- To view the Help topic for this cmdlet online, type: "Get-Help Move-Item -Online" or
               go to https://go.microsoft.com/fwlink/?LinkID=113350.
    

    cmd.exe移动:

    move /?
    Moves files and renames files and directories.
    
    To move one or more files:
    MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination
    
    To rename a directory:
    MOVE [/Y | /-Y] [drive:][path]dirname1 dirname2
    
      [drive:][path]filename1 Specifies the location and name of the file
                              or files you want to move.
      destination             Specifies the new location of the file. Destination
                              can consist of a drive letter and colon, a
                              directory name, or a combination. If you are moving
                              only one file, you can also include a filename if
                              you want to rename the file when you move it.
      [drive:][path]dirname1  Specifies the directory you want to rename.
      dirname2                Specifies the new name of the directory.
    
      /Y                      Suppresses prompting to confirm you want to
                              overwrite an existing destination file.
      /-Y                     Causes prompting to confirm you want to overwrite
                              an existing destination file.
    
    The switch /Y may be present in the COPYCMD environment variable.
    This may be overridden with /-Y on the command line.  Default is
    to prompt on overwrites unless MOVE command is being executed from
    within a batch script.
    
    • 1

相关问题

  • 将前景颜色添加到 Powershell 配置文件?

  • Python 的“pass”参数的批处理等价物是什么?

  • 禁用后无法启用 Microsoft Print to PDF

  • 我可以让这个 PowerShell 脚本接受逗号吗?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve