简体   繁体   English

如何使用批处理文件在Windows上复制open命令的功能?

[英]How to replicate the functionality of the open command on Windows using a batch file?

I'm trying to replicate the functionality of the open command on the mac using Windows batch scripts. 我正在尝试使用Windows批处理脚本在Mac上复制open命令的功能。 Here is what I have so far in my file open.cmd that I have on the PATH : 这是到目前为止我在PATH拥有的文件open.cmd中拥有的内容:

echo off
IF "%1"=="" GOTO HAVE_0
IF "%1"=="." GOTO HAVE_0
IF "%2"=="" GOTO HAVE_1
GOTO ERROR

:HAVE_0
explorer %cd%
GOTO END

:HAVE_1
explorer %1

:ERROR
echo "Incorrect number of arguments."
echo "Please use the command: c:\>open <directory>"
echo "eg c:\>open ."

:END

Now this works. 现在这有效。 I think there must be a better way or something I've missed. 我认为一定有更好的方法或我错过的东西。 Is there a better way? 有没有更好的办法?

My question is: How to replicate the functionality of the open command on Windows using a batch file? 我的问题是: 如何使用批处理文件在Windows上复制open命令的功能?

As eryksun points out, start is very similar to open . 正如eryksun所指出的, startopen非常相似。 You can shorten your script to just this: 您可以将脚本缩短为:

@start "" %*

and I think it'll work mostly as you intend. 而且我认为它基本上可以按照您的预期工作。 If you supply a directory as an argument, the script will open an Explorer window. 如果提供目录作为参数,则脚本将打开资源管理器窗口。 If you supply a URL, it'll open your default web browser. 如果提供URL,它将打开默认的Web浏览器。 If you supply a document, it'll open the document in its associated program. 如果提供文档,它将在其关联程序中打开该文档。

(How's that for code golfing?) (代码打高尔夫球怎么样?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM