简体   繁体   English

将截断的文件名传递给另一个批处理文件

[英]Passing a truncated filename to another batch file

I have a bunch of files in a folder named cores.我在一个名为 cores 的文件夹中有一堆文件。 The files have names like c_000223~a, c_120302~a, etc.这些文件具有 c_000223~a、c_120302~a 等名称。

I have a batch file with a for loop in it.我有一个带有 for 循环的批处理文件。 It should go through each core file and send it to another batch file called RunMSFlux for processing.它应该通过每个核心文件 go 并将其发送到另一个名为 RunMSFlux 的批处理文件进行处理。 The trouble is RunMSFlux doesn't accept the core filenames they are.问题是 RunMSFlux 不接受它们的核心文件名。 It doesn't want the 'c_' at the beginning, just 000223~a, 120302~a, and so on.它不希望开头的“c_”,只需要 000223~a、120302~a 等等。

I can't modify RunMSFlux to accept the 'c_', as it is read-only.我无法修改 RunMSFlux 以接受“c_”,因为它是只读的。 Also, I don't want to rename the core files as they are used by other programs outside of my batch file.另外,我不想重命名核心文件,因为它们被我的批处理文件之外的其他程序使用。 So I need a way to strip off the c_ at the beginning of the filename and then pass that on to RunMSFlux.所以我需要一种方法来去除文件名开头的 c_,然后将其传递给 RunMSFlux。

Here is my batch file so far:到目前为止,这是我的批处理文件:

    @echo on
    set bindirectory=K:\Physics\bin\1112\
    set coredirectory=K:\Physics\cores\
    set quiet=yes

for %%f in ( %coredirectory%* ) do (

    call %bindirectory%\RunMSFlux.bat %%f measbu measbu
)

Is there a way to get the batch file to strip out the c_ first before passing the filename to the for loop?有没有办法让批处理文件在将文件名传递给 for 循环之前先去掉 c_ ? Or perhaps could I create a.txt file with the names of the truncated core files in them and have the script go through it line by line and pass those names off to the for loop?或者,也许我可以创建一个包含截断核心文件名称的 .txt 文件,并让脚本 go 逐行通过,然后将这些名称传递给 for 循环?

After much wailing and gnashing of teeth I believe I finally have something that works:经过多次哭泣和咬牙切齿,我相信我终于有了一些有用的东西:

@echo on
set bindirectory=K:\Physics\bin\1112\
set coredirectory=K:\Physics\cores\
set quiet=yes

for /F "tokens=1* eol=_ delims=_" %%g in ( 'dir /A:-d /B %coredirectory%' ) do (

call %bindirectory%RunMSFlux.bat %%h measbu measbu 
)

The tokens, eol, and delims strip out the c_ in the filenames listed by 'dir /A:-d /B' before passing the truncated filename on to RunMSFlux.bat inside the loop.在将截断的文件名传递给循环内的 RunMSFlux.bat 之前,标记、eol 和 delims 会去除 'dir /A:-d /B' 列出的文件名中的 c_。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM