使用批处理文件在目录/文件夹中创建/放置/保存/存储时打开新文件吗?

发布于 2024-12-19 15:07:41 字数 415 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷乱花海 2024-12-26 15:07:42

假设 %1 是作为参数传递给脚本的文件名,您可以执行以下操作:

IF %~z1 GTR 0 (
  commands to process the file
)

%~z1 计算出 中指定的文件的大小>%1GTR 表示大于,因此条件会检查大小是否大于 0,如果为真,则命令处理文件< /code>被执行。

Assuming %1 is the file name passed to the script as an argument, you could do something like this:

IF %~z1 GTR 0 (
  commands to process the file
)

%~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, the commands to process the file are executed.

智商已欠费 2024-12-26 15:07:42

这个 bach 文件应该可以完成您想要的操作(不确定它是否适用于所有版本的 Windows)。

它使用 Andriy M 的脚本,但添加了您请求的功能。

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET dirname=F:\Files

:Begin
CLS
ECHO %TIME%
FOR /R "%dirname%\" %%a IN (*.zip) DO CALL :process1 %%a
ping.exe localhost -n 11 >nul
GOTO Begin

:process1
IF %~z1 GTR 0 "%1"
GOTO :EOF

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.

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET dirname=F:\Files

:Begin
CLS
ECHO %TIME%
FOR /R "%dirname%\" %%a IN (*.zip) DO CALL :process1 %%a
ping.exe localhost -n 11 >nul
GOTO Begin

:process1
IF %~z1 GTR 0 "%1"
GOTO :EOF

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文