首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在powershell中运行php中查找目录时的错误消息

在powershell中运行php中查找目录时的错误消息
EN

Stack Overflow用户
提问于 2021-08-30 23:43:56
回答 1查看 43关注 0票数 0

首先,请原谅任何语法或拼写错误。英语是我的第二语言,写这篇文章的时候已经是凌晨2点了。我试图创建一个可以在powershell中执行的php脚本,该脚本可以从超级v虚拟机内部执行。此脚本将从与虚拟机共享的驱动器中获取文件,并对这些文件进行散列。

我遵循这个指南来访问共享驱动器。此指南用于在powershell中执行php脚本。为此,需要设置这些环境变量。

下面的代码是我正在尝试执行的代码,它位于:\\tsclient\E\My_Projects\new_code\hashing_script.php

代码语言:javascript
复制
$directory = "\\tsclient\E\My_Projects\new_data";
$directoryContents = scandir("$directory");
$counter = count($directoryContents, 0);
$hashes = [0, 0];
for($i = 2; $i < $counter; $i++)
{
$hash = hash_file("sha512", "$directory\$directoryContents[$i]");
array_push($hashes, $hash);
}
var_dump($hashes);

当我在powershell中使用命令:php.exe \\tsclient\E\My_Projects\new_code\hashing_script.php执行代码时,我会得到以下错误消息:

代码语言:javascript
复制
PHP Warning: scandir(\tsclient\E\My_Projects
ew_data, \tsclient\E\My_Projects
ew_data): Das System kann den angegebenen Pfad nicht finden. (code: 3) in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 2

Warning: scandir(\tsclient\E\My_Projects
ew_data, \tsclient\E\My_Projects
ew_data): Das System kann den angegebenen Pfad nicht finden. (code: 3) in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 2
PHP Warning: scandir(\tsclient\E\My_Projects
ew_data): failed to open dir: No such file or directory in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 2

Warning: scandir(\tsclient\E\My_Projects
ew_data): failed to open dir: No such file or directory in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 2
PHP Warning: scandir(): (errno 2): No such file or directory in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 2

Warning: scandir(): (errno 2): No such file or directory in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 2
PHP Warning: count(): Parameter must be an array or an object that implements Countable in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 3

Warning: count(): Parameter must be an array or an object that implements Countable in \\tsclient\E\My_Projects\new_code\hashing_script.php on line 3
array(2) {
  [0]=>
  int(0)
  [1]=>
  int(0)
}

Das系统kann den angegebenen Pfad nicht finden

是德语,大致翻译为:

系统找不到指定的路径。

关于错误消息,我注意到的两件主要事情是:

  1. 当它返回地址路径时,缺少一个反斜杠。
  2. 它将文件夹名作为\new_code分隔为\n,并在下一行继续。

为了解决这个问题,我有:

  1. 运行其他只回显数据的测试文件,它们将出色地工作。
  2. 尝试从.txt文件中读取dir名称。这会返回一条错误消息,无法找到.txt文件。
  3. 尝试使用$_SERVER‘’DOCUMENT_ROOT‘,这在错误消息中并没有改变很多。

我得出的结论是,powershell/php似乎认为\tsclient\E\My_Projects\new_code\hashing_script.php是一个目录,并试图在其中搜索,这显然是行不通的。

感谢您抽出时间阅读这篇文章,欢迎您提出任何建议/想法/问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-30 23:50:07

你需要养成保护反斜杠的习惯。您的字符串包含\n,当然,它将转换为换行符,而不是您所期望的两个字符。您需要将反斜杠加倍或使用单引号:

代码语言:javascript
复制
$directory = "\\\\tsclient\\E\\My_Projects\\new_data";
$directory = '\\tsclient\E\My_Projects\new_data';
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68991363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档