Batch file 使用批处理脚本检查并列出jpg文件(如果存在于文本文件中)
我有一个项目,它有以下步骤:Batch file 使用批处理脚本检查并列出jpg文件(如果存在于文本文件中),batch-file,command-prompt,Batch File,Command Prompt,我有一个项目,它有以下步骤: 在文件夹中创建jpg文件列表(最初没有) 如果创建的文本文件为空,请转至步骤1 如果步骤1中创建的列表文件不是空的,则启动另一个程序(此程序需要接收的jpg文件作为输入) JPG文件将由另一个进程发送到此文件夹 我不熟悉使用批处理脚本,并从输入中使用了以下代码。 但即使在接收到JPG文件后,该程序也不会按照步骤3中的要求启动另一个进程 我的代码有什么问题 @echo off set "dir=E:\test" set "file=%dir%\a.txt" :st
@echo off
set "dir=E:\test"
set "file=%dir%\a.txt"
:start
dir/b *.jpg>a.txt
if "%~z1" == "" (
goto start
)
if "%~z1" == "0" (
goto start
)
if "%~z1" == "1" (
Start "" "C:\Users\vamsidhar muthireddy\Documents\Visual Studio 2010\Projects\database_test0\Debug\database_test0.exe"
)
dir
,尽管也有命令dir,但不建议这样做start
,尽管也有命令start,但不建议这样做dir
的使用位置,并且批处理文件也包含命令dir,或者想通过运行替换来重命名标签start
,批处理文件也包含命令start,这些操作变得很困难,因为必须对每次发现的事件使用上下文dir
和start
进行分析
另外,批处理文件代码的语法高亮显示在命令DIR和START中肯定是不正确的,因为变量DIR
和标签START
很可能也会作为命令高亮显示
主要的编码错误是%~z1
,因为如果批处理文件是使用现有文件的文件名调用的,则在调用批处理文件时,此错误会被指定为文件名作为第一个参数的文件大小所取代。但事实并非如此。这里的目的是获取列表文件的大小。另外,如果“%~z1”==“1”
几乎永远不会是真的。仅当指定为参数的文件大小正好为1字节时,此条件才变为真
以下是我认为对任务更有用的注释批处理代码:
@echo off
set "SourceDirectory=E:\test"
rem This loop is executed with a delay of 5 seconds between each loop run
rem until at least 1 file with extension JPG is found in the defined source
rem directory. Then the JPG file is processed and batch processing ends.
:Loop
echo Checking for a *.jpg file in %SourceDirectory% ...
if exist "%SourceDirectory%\*.jpg" goto ProcessFile
%SystemRoot%\System32\ping.exe 127.0.0.1 -n 6 >nul
goto Loop
:ProcessFile
for %%I in ("%SourceDirectory%\*.jpg") do (
echo Processing %%I ...
start "" "%USERPROFILE%\Documents\Visual Studio 2010\Projects\database_test0\Debug\database_test0.exe" "%%I"
)
rem Delete the created variable before exiting batch processing.
set "SourceDirectory="
要了解所使用的命令及其工作方式,请打开命令提示符窗口,在其中执行以下命令,并非常仔细地阅读为每个命令显示的所有帮助页面
echo/?
获取/?
goto/?
如果/?
ping/?
rem/?
设置/?
start/?
dir
,尽管也有命令dir,但不建议这样做start
,尽管也有命令start,但不建议这样做dir
的使用位置,并且批处理文件也包含命令dir,或者想通过运行替换来重命名标签start
,批处理文件也包含命令start,这些操作变得很困难,因为必须对每次发现的事件使用上下文dir
和start
进行分析
另外,批处理文件代码的语法高亮显示在命令DIR和START中肯定是不正确的,因为变量DIR
和标签START
很可能也会作为命令高亮显示
主要的编码错误是%~z1
,因为如果批处理文件是使用现有文件的文件名调用的,则在调用批处理文件时,此错误会被指定为文件名作为第一个参数的文件大小所取代。但事实并非如此。这里的目的是获取列表文件的大小。另外,如果“%~z1”==“1”
几乎永远不会是真的。仅当指定为参数的文件大小正好为1字节时,此条件才变为真
以下是我认为对任务更有用的注释批处理代码:
@echo off
set "SourceDirectory=E:\test"
rem This loop is executed with a delay of 5 seconds between each loop run
rem until at least 1 file with extension JPG is found in the defined source
rem directory. Then the JPG file is processed and batch processing ends.
:Loop
echo Checking for a *.jpg file in %SourceDirectory% ...
if exist "%SourceDirectory%\*.jpg" goto ProcessFile
%SystemRoot%\System32\ping.exe 127.0.0.1 -n 6 >nul
goto Loop
:ProcessFile
for %%I in ("%SourceDirectory%\*.jpg") do (
echo Processing %%I ...
start "" "%USERPROFILE%\Documents\Visual Studio 2010\Projects\database_test0\Debug\database_test0.exe" "%%I"
)
rem Delete the created variable before exiting batch processing.
set "SourceDirectory="
要了解所使用的命令及其工作方式,请打开命令提示符窗口,在其中执行以下命令,并非常仔细地阅读为每个命令显示的所有帮助页面
echo/?
获取/?
goto/?
如果/?
ping/?
rem/?
设置/?
start/?