Batch files: Get value out string

March 3, 2009 at 23:21:27
Specs: Windows XP

I receive a file that contains the following

The amount of files in the file and the amount of directories are variable

What I need is the filename. So file1, file2, file3, file4, file5,...

This as I need to perform some actions for each file

Thanks a lot in advance for your help!

See More: Batch files: Get value out string

Report •

March 4, 2009 at 00:09:40
type in command prompt:
for /f %a in ('dir/b/s/a-d') do @echo %~nxa

edit: (didnt notice the file part)
for /f %a in (list.txt) do @echo %~nxa

Report •

March 4, 2009 at 00:19:21
Perfect! Thanks a lot!

Report •

March 9, 2009 at 08:25:26

Hi Vesperdolphin:

Let's say you have the list of files in filelist.txt and you want to print the file names.

The following in biterscripting will do it.

cat filelist.txt

Or, perhaps, more elegantly, the following will do it.

var str filelist ; cat filelist.txt > $filelist
while ($filelist <> "")
lex "1" $filelist

The lex (line extractor) command extracts lines from $filelist one by one.

Although the second form has more code, it will now allow you to do more complex things. I will demonstrate:

Let's say you want to insert first line into each one of those files. The line to be inserted is "THIS IS COMMENT" .

We can now take the above framework and change it as follows.

var str filelist ; cat filelist.txt > $filelist
while ($filelist <> "")
var str file ; lex "1" $filelist > $file
var str content ; cat $file > $content
lin "1" "THIS IS COMMENT\n" $content > $content
echo $content > { echo $file }

The lin command (line inserter) will insert "THIS IS COMMENT\n" before the first line.

The > { echo $file } will redirect the output of echo back to the same file (whose name is in $file).

If you don't have biterscripting, you can download it free at .

I am a scripting trainer, so I like to challenge my students by presenting a framework on which they can do even more complex things than they were originally thinking. Because, as their career advances, they will be called upon to do more complex things .


Report •

Related Solutions

March 17, 2009 at 06:09:06

Report •

Ask Question