views:

43

answers:

1

Hi

I am trying to create a script listing the names of the files return by a program.

The program is called ShowFiles.exe and it takes to arguments like this:

"ShowFiles opened ..." 

so argument 1 is "opened" and argument 2 is "..."

The the result looks like this:

c:\tmp\test1.txt#0 - add default 
c:\tmp\test2.TXT#1 - edit default 

What i want is to only get the names of the files.

Like this:

test1.txt 

test2.txt 

Thanks alot for any help.

+3  A: 

You can use for /f to iterate over the command output:

for /f %%F in ('ShowFiles ...') do ...

This can take some options that control how tokenizing will be done. In your case, the file name apparently stops at a #, so the following should split at # and only take the first token:

for /f "tokens=1 delims=#" %%F in ('ShowFiles ...') do (
    echo File name: %%F
    echo File name without path: %%~nxF
)

You can then use the file names as shown above for whatever you need. If you just need to output them, then a simple echo %%F or echo %%~nxF will suffice. More detail on those things can be found in help for.

Joey