使用批处理文件在目录/文件夹中创建/放置/保存/存储时打开新文件吗?
Stack Overflow 上的朋友们大家好!
我在互联网上搜索了很多,但没有得到任何相关的信息。
我正在编写一个脚本,该脚本一旦放置在目录中就可以直接打开文件。假设我有目录:
F:\Files
现在我将文件下载到该文件夹。将创建以下内容:
F:\Files\download.zip REM This is the actual file, but 0 KB
F:\Files\download.part REM This is the content of the *.zip, until it is fully downloaded.
那么,当 download.zip 的大小大于 1 字节时,我可以使用哪个脚本来打开它?
Hello people on Stack Overflow!
I've searched a lot on the internet, but I didn't get anything relevant.
I am writing a script that opens a file directly once placed in directory. So let's say I have the directory:
F:\Files
Now I download a file to that folder. The following will be created:
F:\Files\download.zip REM This is the actual file, but 0 KB
F:\Files\download.part REM This is the content of the *.zip, until it is fully downloaded.
So which script could I use to open download.zip when its size equals larger than 1 byte?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设
%1
是作为参数传递给脚本的文件名,您可以执行以下操作:%~z1
计算出中指定的文件的大小>%1
。GTR
表示大于,因此条件会检查大小是否大于 0,如果为真,则命令处理文件< /code>
被执行。
Assuming
%1
is the file name passed to the script as an argument, you could do something like this:%~z1
evaluates to the size of the file specified in%1
.GTR
means greater than, so the condition checks if the size is greater than 0, and if that is true, thecommands to process the file
are executed.这个 bach 文件应该可以完成您想要的操作(不确定它是否适用于所有版本的 Windows)。
它使用 Andriy M 的脚本,但添加了您请求的功能。
ping.exe localhost -n 11 >nul
只是一个延迟,这样您就可以让批处理文件保持运行状态,并且它将按照-n 11< 的定义每 10 秒循环一次/code> 会导致以 1 秒为间隔对本地主机进行 11 次 ping 操作,并且在几微秒后第一个操作已成功。
我添加了命令行
ECHO %TIME%
,以便可以看到它仍在工作,因为该时间值会更新每次循环迭代。这种批处理解决方案有一个缺点。如果下一次循环运行时 ZIP 文件仍在目录中,则会再次打开 ZIP 文件。
This bach file should do what you want (not sure if it will work on all versions of Windows).
It is using Andriy M's script, but adds the functionality you requested.
The
ping.exe localhost -n 11 >nul
is just a delay, so that you can leave the batch file running and it will loop about every 10 seconds as defined with-n 11
which results in 11 pings of local host in intervals of 1 second with first one successful already after some microseconds.I've added the command line
ECHO %TIME%
so that it can be seen it is still working as this time value updates every loop iteration.There is a drawback to this batch solution. If the ZIP file is still in the directory when the next loop run occurs, it opens the ZIP file once again.