系统找不到路径,即使它存在于路径中 [英] System cannot find path even though it exists in paths

查看:69
本文介绍了系统找不到路径,即使它存在于路径中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在处理一个调用另一个批处理文件的批处理文件.

Working on a batch file that calls another batch file.

K:\Market Risk>call "K:\Market Risk\activate.bat"
The system cannot find the path specified.

因此,我将路径设置在批处理文件的开头,并确保该路径在其中:

So I set the path at the beginning of my batch file and made sure it was there:

SET PATH=%PATH%;K:\Market Risk\

K:\Market Risk>echo %PATH%
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;
C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Shoreline Communications\
ShoreWare Client\;C:\Program Files\dotnet\;C:\Program Files (x86)\Microsoft SQL Server
\150\DTS\Binn\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\
WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\
Shoreline Communications\ShoreWare Client\;C:\Program Files (x86)\Common Files\Oracle\
Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;
C:\Program Files (x86)\Shoreline Communications\ShoreWare Client\;
C:\Users\Kyle.Dixon\AppData\Local\Microsoft\WindowsApps;C:\Users\Kyle.Dixon\AppData\Local\
Programs\Git\cmd;C:\Users\Kyle.Dixon\AppData\Local\atom\bin;C:\Users\Kyle.Dixon\Documents\
R\R-3.5.2\bin\R.exe;C:\Users\Kyle.Dixon\Documents\R\R-3.5.2\bin;C:\Users\Kyle.Dixon\
AppData\Roaming\MarketView\MarketView ExcelTools\;K:\Market Risk\

但是,我仍然遇到相同的错误:

However, I'm still getting the same error:

K:\Market Risk>call "K:\Market Risk\activate.bat"
The system cannot find the path specified.

以前有人遇到过这个问题吗?

Has anyone had this issue before?

推荐答案

我建议阅读什么是"X不是"的原因识别为内部或外部命令,可操作程序或批处理文件"?应该有助于了解Windows如何管理环境变量 PATH .不幸的是,由于没有可用的命令来安全地添加/删除系统用户 PATH的文件夹路径,因此Windows无法很好地管理它会导致很多问题.缺少由Microsoft编写的用于通过应用所有必要的错误检查来安全更新 PATH 的命令或可执行文件的结果是,许多编码不好的脚本经常破坏系统和<尝试更新Windows注册表中存储的strong>用户 PATH .

I recommend reading What is the reason for "X is not recognized as an internal or external command, operable program or batch file"? It should help to understand how the environment variable PATH is managed by Windows. It is unfortunately not really good managed by Windows which cause lots of problems because of no command is available to safely add/remove a folder path to system or user PATH. The result of missing such a command or executable written by Microsoft to safely update PATH with applying all necessary error checks is lots of not good coded scripts which quite often corrupt system and user PATH stored in Windows registry on trying to update them.

我的建议是以管理员身份打开Windows 控制面板-系统-高级系统设置-环境变量,并清除用户路径 Path strong> Path (上部窗格)和系统 Path (下部窗格),如下所示:

My recommendation is opening Windows Control Panel - System - Advanced System Settings - Environment Variables as administrator and cleaning up both Path environment variables, the user Path (upper pane) and the system Path (lower pane) as follows:

  • 系统 路径应始终从以下默认Windows文件夹路径开始:
    • %SystemRoot%\ System32
    • %SystemRoot%
    • %SystemRoot%\ System32 \ Wbem
    • %SystemRoot%\ System32 \ WindowsPowerShell \ v1.0 \
    • %SystemRoot%\ System32 \ OpenSSH \
    • The system Path should start always with following default Windows folder paths:
      • %SystemRoot%\System32
      • %SystemRoot%
      • %SystemRoot%\System32\Wbem
      • %SystemRoot%\System32\WindowsPowerShell\v1.0\
      • %SystemRoot%\System32\OpenSSH\
      • C:\ Program Files(x86)\ Common Files \ Oracle \ Java \ javapath
      • C:\ Program Files(x86)\ Shoreline Communications \ ShoreWare Client \
      • C:\ WINDOWS
      • C:\ WINDOWS \ system32
      • C:\ WINDOWS \ System32 \ OpenSSH \
      • C:\ WINDOWS \ System32 \ Wbem
      • C:\ WINDOWS \ System32 \ WindowsPowerShell \ v1.0 \

      在清理了两个 Path 环境变量之后,系统中的文件夹路径应该类似于:

      After cleanup of both Path environment variables the folder paths in system Path should be something like:

      • %SystemRoot%\ system32
      • %SystemRoot%
      • %SystemRoot%\ System32 \ Wbem
      • %SystemRoot%\ System32 \ WindowsPowerShell \ v1.0 \
      • %SystemRoot%\ System32 \ OpenSSH \
      • %CommonProgramFiles(x86)%\ Oracle \ Java \ javapath
      • %ProgramFiles(x86)%\ Microsoft SQL Server \ 150 \ DTS \ Binn
      • %ProgramFiles(x86)%\ Shoreline Communications \ ShoreWare客户端
      • C:\ Program Files \ dotnet

      对于最后一个路径,最好保留 C:\ Program Files ,不要使用%ProgramFiles%,除非存在 C:\ Program Files我不知道的\ dotnet C:\ Program Files(x86)\ dotnet ,因为我的Windows计算机上没有这样的目录.出于此原因,请参阅Microsoft文档页面 WOW64实现详细信息.

      For the last path it is better to keep C:\Program Files and do not use %ProgramFiles%, except there is C:\Program Files\dotnet and C:\Program Files (x86)\dotnet which I don't know as I don't have such a directory on my Windows computer. For the reason see the Microsoft documentation page WOW64 Implementation Details.

      用户 路径最终应类似于:

      • %LocalAppData%\ atom \ bin
      • %LocalAppData%\ Microsoft \ WindowsApps
      • %LocalAppData%\ Programs \ Git \ cmd
      • %AppData%\ MarketView \ MarketView ExcelTools
      • %UserProfile%\ Documents \ R \ R-3.5.2 \ bin

      关于在其中执行两个批处理文件的环境的文章很少.所以下面写的大多数都是纯投机性的.

      There is not much written about environment in which the two batch files are executed. So most written below is pure speculative.

      我想驱动器 K:不是本地硬盘上的驱动器,而是网络驱动器.因此,由于网络资源未映射到驱动器号 K:而存在映射到驱动器 K:的网络资源当前不可用,或者存在网络连接问题或网络资源许可问题.

      I suppose that drive K: is not a drive on a local hard disk, but a network drive. So it is possible that the network resource mapped to drive K: is currently not available either because of network resource not mapped to drive letter K: or there is network connection issue or a network resource permission issue.

      Windows仅在用户登录时才将网络资源重新映射到驱动器号,因为网络驱动器映射是Windows在Windows注册表中存储的与用户帐户相关的映射.因此,如果批处理文件是使用其他帐户按计划任务执行的,或者还针对未登录的用户执行,则驱动器 K:确实不存在.必须将执行批处理文件的计划任务配置为使用该帐户,该帐户具有访问该批处理文件访问的所有网络资源和本地目录/文件所必需的权限.此外,还必须使用其UNC路径访问网络资源上的文件和文件夹,而不是使用在这种环境下执行批处理文件时不存在的网络驱动器的驱动器号 K:.

      Windows remaps a network resource to a drive letter as once done by the user only on logon of the user because of network drive mappings are user account related stored by Windows in Windows registry. So if the batch file is executed as scheduled task with using a different account or also on user not logged in, the drive K: does indeed not exist. The scheduled task executing the batch file must be configured to use the account which has the necessary permissions to access all network resources and local directories/files which are accessed by the batch file. And it is additionally necessary to access files and folders on a network resource with their UNC paths instead of using drive letter K: of network drive not existing on execution of the batch file in this environment.

      另请参阅:在将批处理文件作为计划任务执行时必须考虑什么?

      但是也可能是错误消息

      系统找不到指定的路径.

      The system cannot find the path specified.

      在处理包含命令行的批处理文件时, cmd.exe 不会输出

      is not output by cmd.exe on processing the batch file containing the command line

      call "K:\Market Risk\activate.bat"
      

      但在处理批处理文件 K:\ Market Risk \ activate.bat 时执行的命令行上.

      but on a command line executed on processing the batch file K:\Market Risk\activate.bat.

      因此,我建议从两个批处理文件的顶部 @echo off 删除或将其更改为 @echo on 并在命令提示符窗口中运行主批处理文件,请参见调试批处理文件.然后应该100%清除哪个批处理文件中的哪个命令行负责此错误消息.

      Therefore I suggest to remove from both batch files @echo off at top or change it to @echo on and run main batch file from within a command prompt window, see debugging a batch file. Then it should be 100% clear which command line in which batch file is responsible for this error message.

      这篇关于系统找不到路径,即使它存在于路径中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆