首先,请原谅任何语法或拼写错误。英语是我的第二语言,写这篇文章的时候已经是凌晨2点了。我试图创建一个可以在powershell中执行的php脚本,该脚本可以从超级v虚拟机内部执行。此脚本将从与虚拟机共享的驱动器中获取文件,并对这些文件进行散列。
我遵循这个指南来访问共享驱动器。此指南用于在powershell中执行php脚本。为此,需要设置这些环境变量。
下面的代码是我正在尝试执行的代码,它位于:\\tsclient\E\My_Projects\new_code\hashing_script.php
$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执行代码时,我会得到以下错误消息:
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
是德语,大致翻译为:
系统找不到指定的路径。
关于错误消息,我注意到的两件主要事情是:
为了解决这个问题,我有:
我得出的结论是,powershell/php似乎认为\tsclient\E\My_Projects\new_code\hashing_script.php是一个目录,并试图在其中搜索,这显然是行不通的。
感谢您抽出时间阅读这篇文章,欢迎您提出任何建议/想法/问题。
发布于 2021-08-30 23:50:07
你需要养成保护反斜杠的习惯。您的字符串包含\n,当然,它将转换为换行符,而不是您所期望的两个字符。您需要将反斜杠加倍或使用单引号:
$directory = "\\\\tsclient\\E\\My_Projects\\new_data";
$directory = '\\tsclient\E\My_Projects\new_data';https://stackoverflow.com/questions/68991363
复制相似问题