我有一些sgm文件,其中文件名包含空格和逗号。那么,如何将所有sgm文件逐行发送到命令提示符下的转换程序?
示例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=发布于 2015-01-13 11:54:24
只有一段代码的摘录。在所有文件中都会出现同样的问题。
%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,而不是使用将检索扩展名的%~1,而是使用%~n1,只检索文件名。当然,所有被引用的空格都是存在的。
行为
echo %VPIDTD%\decl.sgm > %1.arg应该是
echo %VPIDTD%\decl.sgm > "%~n1.arg"所有批处理文件都需要进行等效的更改。
进行所有更改后,命令行调用将处理所有文件。
for %a in (*.sgm) do table2srt.bat "%a"https://stackoverflow.com/questions/27920692
复制相似问题