使用批处理脚本传递文件名包含空格和逗号的 sgm 文件

Passing sgm files in which the filenames contain spaces and comma using batch script

我有一些文件名包含空格和逗号的 sgm 文件。那么如何在命令提示符下将所有 sgm 文件逐行发送到转换程序?

  1. 如何发送文件名中包含空格和逗号的目录中的 SGM 文件列表?

  2. 如何忽略那些空格和逗号如下所示:

示例 SGM 文件:

Medco Health Solutions, Inc.  No Action, Interpretive and or Exemptive Letter of August 13, 2002.sgm

MP Environmental Funding LLC, PE Environmental Funding LLC  No Action, Interpretive and or Exemptive Letter of September 19, 2007.sgm

Nationwide Financial Services, Inc. and Provident Mutual Life Insurance Company  No Action, Interpretive and or Exemptive Letter of August 9, 2002.sgm

我的运行代码:

c:\Work> table2srt.bat "Medco Health Solutions, Inc.  No Action, Interpretive and or Exemptive Letter of August 13, 2002.sgm"

输出:

Error cannot open Medco.tables

非常感谢对此的任何帮助!!!

批号:(table2srt.bat)

@echo off

rem **************************************************
rem    Check USAGE
rem **************************************************
if "%1" == ""  GOTO USAGE

set rat=%4
if "%4" == "" set rat=1.75

set wid=%5
if "%5" == "" set wid=78

set maxw=%6
if "%6" == "" set maxw=100


echo.
echo ***********************************************************
echo Get all the tables from the file %1.sgm                   
echo ***********************************************************
echo.
echo Program     : %VPISRC%\srt_tables.pl
echo Input File  : %1.sgm
echo Output File : %1.tables
%OMNIDIR%\Perl\bin\perl.exe srt_tables.pl %1.sgm


for %%F in (%1.tables) do (
if %%~zF equ 0 goto NOTABLE
)


echo.
echo *****************************************************
echo Conversion of tables completed successfully         
echo ***************************************************** 
echo.
echo *****************************
echo Convert SGML Table to Perl
echo *****************************
echo   Program        : %VPISRC%\table2srt.om5
echo   DTD            : %VPIDTD%\tabledoc.dtd
echo   Input File     : %1.tables
echo   Ratio          : %rat%
echo   Ideal Width    : %wid%
echo   Maximum Width  : %maxw%
echo   Output File    : %1.prl

echo.

echo %VPIDTD%\decl.sgm              > %1.arg
echo %VPIDTD%\tabledoc.dtd          >> %1.arg
echo %1.tables                          >> %1.arg
echo -s %VPISRC%\table2srt.om5          >> %1.arg
echo -of %1.prl                     >> %1.arg
echo -d ratio %rat%                 >> %1.arg
echo -d max-width %maxw%            >> %1.arg
echo -d ideal-width %wid%           >> %1.arg
echo -d FN %1                       >> %1.arg
echo -l %VPIDTD%/                   >> %1.arg
echo -alog %1.log                   >> %1.arg
echo -i %VPINCLD%\          >> %1.arg

%OMNIDIR%\omnimark -f %1.arg

if errorlevel 4 goto REPORT


rem *********************************************************
rem    Run the Perl script
rem *********************************************************
:PERL
echo.
echo Perform Perl Script....
echo   Input File  : %1.prl
echo   Output File : %1.srt
echo.

%OMNIDIR%\Perl\bin\perl %1.prl > %1.srt

if errorlevel 1 goto BUMMER



echo.
echo Done.
echo.

rem *********************************************************
rem    Merge SRT
rem *********************************************************
echo.
echo Merge SRT Table back in
echo   Program        : %VPISRC%\mrgsrt.om5
echo   Input File     : %1.sgm
echo   SRT File       : %1.srt
echo   Output File    : %1.fnl
echo   Log File       : %1.log
echo.

echo %1.sgm                      > %1.arg
echo -s %VPISRC%\mrgsrt.om5    >> %1.arg
echo -of %1.fnl                >> %1.arg
echo -d FN %1                  >> %1.arg
echo -log %1.log               >> %1.arg
echo -i %VPINCLD%\      >> %1.arg

%OMNIDIR%\omnimark -f %1.arg

if errorlevel 1 goto BUMMER


echo.
echo Done.
echo.


rem *******************************************
rem  SRT Cleanup 
rem *******************************************
echo Program     : %VPISRC%\srt_cleanup.pl
echo Input File  : %1.fnl
echo Output File : %1.sgm
%OMNIDIR%\Perl\bin\perl.exe srt_cleanup.pl %1.fnl

echo.
echo *****************************************************
echo Conversion of table to srt completed successfully   
echo *****************************************************

echo.
echo *****************************************************
echo  Secnal Conversion Completed with final
echo  output file as %1.sgm  
echo *****************************************************

if exist %1.srt del %1.srt
if exist %1.arg del %1.arg
if exist %1.err del %1.err
if exist %1.prl del %1.prl
if exist %1.log del %1.log
if exist %1.tables del %1.tables
if exist %1.fnl del %1.fnl
goto DONE



:NOTABLE
echo *************************************************************
echo No Tables exists in this file  %1.sgm     
echo *************************************************************
echo.
echo *****************************************************
echo  Secnal Conversion Completed with final
echo  output file as %1.sgm  
echo *****************************************************
goto DONE 

:BUMMER
echo Bummer....
echo Check %1.log
echo.
goto DONE

:REPORT
echo.
echo Bummer. Unexpected Conversion Errors.
echo Check %1.err
echo.
goto DONE

::USAGE
echo.
echo USAGE is TABL2SRT (FILENAME) (SGM)
echo    Optional: (RATIO) (IDEAL WIDTH) (MAXIMIM WIDTH)
echo.
goto DONE

:DONE
set rat=
set wid=
set maxw=

只是代码中的一个摘录。所有文件都出现同样的问题

%OMNIDIR%\Perl\bin\perl.exe srt_tables.pl %1.sgm


for %%F in (%1.tables) do (
if %%~zF equ 0 goto NOTABLE
)

%1 包含带扩展名的带引号的文件名,因此解析器解释的是

c:\somewhere\Perl\bin\perl.exe srt_tables.pl "Medco Health .... 2002.sgm".sgm

for %%F in ("Medco Health .... 2001.sgm".tables) do (
if %%~zF equ 0 goto NOTABLE
)

应该是这样的

"%OMNIDIR%\Perl\bin\perl.exe" srt_tables.pl "%~1"

传递完整的文件名,不带引号(从这里开始 %~1 而不是 %1)并再次引用(以防万一您最初忘记了引号)。

perl 程序属性 会生成输出文件吗?假设它能正常工作,那么下一个代码应该是

for %%F in ("%~n1.tables") do (
    if %%~zF equ 0 goto NOTABLE
)

似乎(从您的代码中)perl 程序生成了一个具有相同名称但扩展名替换为 .tables 的文件,而不是使用 %~1 来检索名称扩展名,使用 %~n1,仅检索文件名。而且,当然,所有引用为空格都存在。

行为

echo %VPIDTD%\decl.sgm              > %1.arg

应该是

echo %VPIDTD%\decl.sgm              > "%~n1.arg"

所有批处理文件都需要进行等效更改。

完成所有更改后,命令行调用处理所有文件

for %a in (*.sgm) do table2srt.bat "%a"