1.

Solve : Create batch file to insert text into multiple txt files??

Answer»

Hi All!!

Newb here with another newb question 

I have been at this for the last 10 hours. It's 4:38am Hawaii time and I am not going to sleep till I figure this out :-)

I have 4,000 dummy files in one of my pc folders that I need to add text to. They are all empty txt files right now and I just need to insert text that says "This is a placeholder file. You may delete this file if you wish."

I tried creating a run.cmd file.........but I don't know what the heck I am doing :-) I started doing it by hand and by the time I got 700......I was like "this is stupid, there has to be an easier way."

So here I am!

Any help would be greatly appreciated!!!!1

Thanks!!

CourtneyDo you need 700 files with the same text but unique files names?
Does each file have to have a variation fro the text?
You can do it in batch, but using almost any script language other than batch is easier fro most people.
It can be done with a FOR loop, but the syntax of batch FOR loops is HARD to remember, unless you do it every day.
Do you use any script language? JavaScript, VBScript
Here is a short list.
http://isystemadmin.com/list-of-popular-scripting-languages-for-linux-and-windows
That site happens to mention SED, a program that has been  ported to Windows and can be used with DOS commands to manipulate text and file names.
But if you really want the DOS only batch file, just want as few minuets.
The EXPERT is coming. Just wait.if you have a list of the files :
Code: [Select]for /f "delims=" %%A in ('type "ListOfLocations.txt"') do (

cd %%A
for /f "delims=" %%B in ('type "ListOfFileNames.txt"') do (
if exist %%B ECHO This is a placeholder file. You may delete this file if you wish. >>%%B
echo Wrote to %%A\%%B.
)
)

if they are all in the same place:
Code: [Select]for /f "delims=" %%A in ('dir /b *.txt') do (
echo This is a placeholder file. You may delete this file if you wish. >>%%A
)

I hope this helps.for /f "delims=" %%A in ('dir /b *.txt') do (
echo This is a placeholder file. You may delete this file if you wish. >>%%A
)

I am accessing files on the network path and DIR command causes some issues.
Can anyone rewrite the program replacing DIR?

ThankyouI don't do much with NETWORKS, but try looking into the command 'pushd'.



Discussion

No Comment Found