Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 在目录名中的脚本中使用通配符_Windows_Shell_Scripting_Wildcard - Fatal编程技术网

Windows 在目录名中的脚本中使用通配符

Windows 在目录名中的脚本中使用通配符,windows,shell,scripting,wildcard,Windows,Shell,Scripting,Wildcard,我正在编写一个脚本,其中我想将一个文件从我的目录复制到计算机中的“开始菜单\程序\启动”。 我的问题是-此脚本适用于多台计算机,由于某些原因,每台计算机中的管理员都有不同的名称,因此路径“C:\Documents and Settings*administrator*\Start Menu\Programs\Startup”不适用于所有计算机 我正在寻找一种在目录名中使用通配符的方法。比如: “C:\Documents and Settings\administrator*\Start Menu

我正在编写一个脚本,其中我想将一个文件从我的目录复制到计算机中的“开始菜单\程序\启动”。 我的问题是-此脚本适用于多台计算机,由于某些原因,每台计算机中的管理员都有不同的名称,因此路径“C:\Documents and Settings*administrator*\Start Menu\Programs\Startup”不适用于所有计算机

我正在寻找一种在目录名中使用通配符的方法。比如: “C:\Documents and Settings\administrator*\Start Menu\Programs\Startup”,因此我的脚本可以在所有计算机上运行。(这个名字在advance中是未知的,但我知道它将以“administrator”一词开头)

有什么想法吗? 谢谢


Tamar

可能有更聪明的方法,但其中一种方法是使用
for
命令。如下所示:

cd "c:\documents and settings"
for /D %%f in (administrator*) do copy yourfile "%%f\start menu\programs\startup"
可能是变量

%userprofile%

可能对你有用。它直接为您提供路径“C:\Documents and Settings\CurrentLoggedUser”。

我正在尝试编写:fileCopy(“C:\MyDir\MyFile”,%userprofile%\start menu\Programs\Startup),但它不起作用。怎么了?请尝试echo%userprofile%查看您得到了什么。您可能需要使用引号:“%userprofile%\start menu\Programs\Startup”@Tamar:%userprofile%不一定在cmd.exe以外的脚本环境中以这种方式可用。它是一个环境变量,需要这样访问。例如,在vbscript中:
userprofile=createobject(“WScript.Shell”).expandEnvironmentString(“%userprofile%”)