Computing.Net > Forums > Programming > Simple Batch - prepend filename

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Simple Batch - prepend filename

Reply to Message Icon

Name: gometro33
Date: August 5, 2006 at 10:42:28 Pacific
OS: xp
CPU/Ram: 3ghz // 1gb
Product: selfbuilt
Comment:

I have about 3000 .txt files that need to have their filename (without the .txt) added to the beginning of the file, and also surrounded by [B] and [/B]. Example:

file1.txt contains "Hello computing.net!"

After processing file1.txt contains

"[B]file1[/B]

Hello computing.net!"

Thanks guys!

-Matt



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: August 5, 2006 at 11:30:58 Pacific
Reply:

Hi
@echo off

dir c:\xxx\*.bat /b > ~Tmp1.txt

for /f %%a in (~Tmp1.txt) do (
echo [B]%%~na[/B] > ~Tmp2.txt
type c:\xxx\%%a >> ~Tmp2.txt
type ~Tmp2.txt > c:\xxx\%%a
)
del ~Tmp?.txt



0

Response Number 2
Name: Mechanix2Go
Date: August 5, 2006 at 11:31:39 Pacific
Reply:

::== matt.bat
@echo off
for /f %%B in ('dir/b *.txt') do (
echo [B]%%~nB[/B] > #
copy /b #+%%B ## > nul
type ## > %%B
)
::== DONE


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 3
Name: gometro33
Date: August 5, 2006 at 11:45:17 Pacific
Reply:

erm M2, that didn't work...I just put that in the folder with the txt files right?

And dtech10, what do I need to change for that to work for me?

-Matt


0

Response Number 4
Name: Mechanix2Go
Date: August 5, 2006 at 12:37:12 Pacific
Reply:

"erm M2, that didn't work"

What did it *DO* ?


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 5
Name: gometro33
Date: August 5, 2006 at 12:45:42 Pacific
Reply:

It created 3 files #, ##, and Set (no extensions).

# contains [B]Set[/B]
## and Set have [B]Set[/B] over and over (on new lines -- I assume there's one line for each file...)

Then it did nothing to the original files.

-Matt


0

Related Posts

See More



Response Number 6
Name: gometro33
Date: August 5, 2006 at 12:47:58 Pacific
Reply:

Crap, I know what's wrong. There are spaces in the filenames and the first hundred txt files start with Set. Anyway to get around this?

-Matt


0

Response Number 7
Name: Mechanix2Go
Date: August 5, 2006 at 12:54:54 Pacific
Reply:

I have no idea how it created a file named set. The word set is not in the batch script.

What does this do:

dir/b *.txt


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 8
Name: gometro33
Date: August 5, 2006 at 13:09:39 Pacific
Reply:

See response #6. There are spaces in the filenames.

-Matt


0

Response Number 9
Name: Mechanix2Go
Date: August 5, 2006 at 13:27:07 Pacific
Reply:

As a;ways, LFNs are a bad odea.

::== e4.bat
@echo off
for /f "tokens=*" %%B in ('dir/b *.txt') do (
echo [B]%%~nB[/B] > #
copy /b #+"%%B" ## > nul
type ## > "%%B"
)
:: DONE


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 10
Name: gometro33
Date: August 5, 2006 at 13:31:26 Pacific
Reply:

Thank you so much, works like a charm!!

-Matt


0

Sponsored Link
Ads by Google
Reply to Message Icon

VB6: force app to stay in... Uplaod Service



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Simple Batch - prepend filename

Batch log filename www.computing.net/answers/programming/batch-log-filename/15108.html

Simple Batch Script www.computing.net/answers/programming/simple-batch-script/16428.html

Simple Batch file www.computing.net/answers/programming/simple-batch-file/10948.html