A Windows XP help forum. PCbanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » PCbanter forum » Windows 10 » Windows 10 Help Forum
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Adding one line to a directory full of text files



 
 
Thread Tools Rate Thread Display Modes
  #1  
Old June 8th 17, 05:24 PM posted to alt.comp.os.windows-10
Chaya Eve
external usenet poster
 
Posts: 202
Default Adding one line to a directory full of text files

I need to add a line to a directory full of text files with the same
extension (which isn't .txt but I don't know if that matters).

Is there an easy way in Windows 10 to run a command that does this?

Pseudocode:
If the file name ends in xxx and if the last line isn't "do this",
then add a line of "do this".

Alternatively, I can just blindly add "do this" to the end of all files
in the directory, since having the directive twice won't hurt anything.

Any suggestions for a simple way to do this for a non programmer?
Ads
  #2  
Old June 8th 17, 05:56 PM posted to alt.comp.os.windows-10
Good Guy[_2_]
external usenet poster
 
Posts: 3,354
Default Adding one line to a directory full of text files

On 08/06/2017 17:24, Chaya Eve wrote:
I need to add a line to a directory full of text files with the same
extension (which isn't .txt but I don't know if that matters).

Is there an easy way in Windows 10 to run a command that does this?

Pseudocode:
If the file name ends in xxx and if the last line isn't "do this",
then add a line of "do this".

Alternatively, I can just blindly add "do this" to the end of all files
in the directory, since having the directive twice won't hurt anything.

Any suggestions for a simple way to do this for a non programmer?

Perhaps you need to use "Group by" sort order. To do this change your
view to "Details" then look for something like this:

https://i.cubeupload.com/gI4KhX.png https://i.cubeupload.com/gI4KhX.png

--
With over 500 million devices now running Windows 10, customer
satisfaction is higher than any previous version of windows.

  #4  
Old June 8th 17, 09:07 PM posted to alt.comp.os.windows-10
Big Al[_7_]
external usenet poster
 
Posts: 177
Default Adding one line to a directory full of text files

On 06/08/2017 12:24 PM, Chaya Eve wrote:
I need to add a line to a directory full of text files with the same
extension (which isn't .txt but I don't know if that matters).

Is there an easy way in Windows 10 to run a command that does this?

Pseudocode:
If the file name ends in xxx and if the last line isn't "do this",
then add a line of "do this".

Alternatively, I can just blindly add "do this" to the end of all files
in the directory, since having the directive twice won't hurt anything.

Any suggestions for a simple way to do this for a non programmer?

One fly in the ointment is how you view/sort the directory as to what is
"last" line!

  #5  
Old June 8th 17, 09:28 PM posted to alt.comp.os.windows-10
Chaya Eve
external usenet poster
 
Posts: 202
Default Adding one line to a directory full of text files

On Thu, 8 Jun 2017 16:07:01 -0400, Big Al wrote:

One fly in the ointment is how you view/sort the directory as to what is
"last" line!


I must have confused everyone so I will clarify that I just one to add a
single line to each file in a directory of a given file type.

So if there are a hundred files in any given directory that are called
file1.abc
file2.abc
file3.abc
etc

I just want to add one line to each of those files.
For each file that ends with the extension abc
add this one command to that file if that command isn't already there
"do this"

What's the best way to do that on Windows 10?
  #6  
Old June 8th 17, 09:28 PM posted to alt.comp.os.windows-10
Chaya Eve
external usenet poster
 
Posts: 202
Default Adding one line to a directory full of text files

On Thu, 8 Jun 2017 16:08:12 -0300, pjp
wrote:

I have no idea what you mean by "add a line to a directory"?


I am sorry I wasn't clear as nobody got it and that means I said it wrong.

I just want to add one line to *each* file in a directory full of files.

For example, before I run the command, this is the content of file1.abc:
c:\ type file1.abc
do one thing
do another
do something else

This would be the result on each file after I run the desired command:
c:\ type file1.abc
do one thing
do another
do something else
do this
  #7  
Old June 8th 17, 09:28 PM posted to alt.comp.os.windows-10
Chaya Eve
external usenet poster
 
Posts: 202
Default Adding one line to a directory full of text files

On Thu, 8 Jun 2017 17:56:11 +0100, Good Guy
wrote:

Perhaps you need to use "Group by" sort order. To do this change your
view to "Details" then look for something like this:

https://i.cubeupload.com/gI4KhX.png


I must have explained it all wrong, as my problem has nothing to do with a
"directory". It's just that files are in directories.

My problem is only about adding a single line to a file.
There can be hundreds of these files in any one directory.

Let's say the file names a
file1.abc
file2.abc
file3.abc
file4.abc
etc

And let's say each of those files contains a script of the format:
(line 1) do one thing
(line 2) do another
(line 3) do something else
etc

All I want to do is *append* a new command to each of those files.
That way, each file has one more line.

For example, before I run the command, this is the content of file1.abc:
c:\ type file1.abc
do one thing
do another
do something else

This would be the desired result of all the files after I run the command:
c:\ type file1.abc
do one thing
do another
do something else
do this

Notice that all I want to do is add "do this" to the end of every file that
is in a directory that ends with the filename extension of "abc".

What's the easiest way to do that on Windows 10?
  #8  
Old June 8th 17, 09:55 PM posted to alt.comp.os.windows-10
Big Al[_7_]
external usenet poster
 
Posts: 177
Default Adding one line to a directory full of text files

On 06/08/2017 04:28 PM, Chaya Eve wrote:
On Thu, 8 Jun 2017 16:08:12 -0300, pjp
wrote:

I have no idea what you mean by "add a line to a directory"?


I am sorry I wasn't clear as nobody got it and that means I said it wrong.

I just want to add one line to *each* file in a directory full of files.

For example, before I run the command, this is the content of file1.abc:
c:\ type file1.abc
do one thing
do another
do something else

This would be the result on each file after I run the desired command:
c:\ type file1.abc
do one thing
do another
do something else
do this

So you want to look at every file that has the ABC extension and if "do
this" is not at the end of that file, you want to add "do this" to the
end of the file.


  #9  
Old June 8th 17, 10:23 PM posted to alt.comp.os.windows-10
Chaya Eve
external usenet poster
 
Posts: 202
Default Adding one line to a directory full of text files

On Thu, 8 Jun 2017 16:55:25 -0400, Big Al wrote:

So you want to look at every file that has the ABC extension and if "do
this" is not at the end of that file, you want to add "do this" to the
end of the file.


Yes. Thanks for asking for confirmation of the problem.
Sorry I wasn't clear at first.
What's the easiest way on Windows 10 for a non programmer to set this up?
  #10  
Old June 8th 17, 10:27 PM posted to alt.comp.os.windows-10
Nil[_5_]
external usenet poster
 
Posts: 1,731
Default Adding one line to a directory full of text files

On 08 Jun 2017, Chaya Eve wrote in
alt.comp.os.windows-10:

Notice that all I want to do is add "do this" to the end of every
file that is in a directory that ends with the filename extension
of "abc".

What's the easiest way to do that on Windows 10?


I'm sure you could put together a batch file that would step through a
directory of text files using the FOR and DO commands, and append
another text file ("DoThis.txt") to the end of each, the 2nd text file
contining only the line "do this" using the COPY command, like

COPY file1.abc+DoThis.txt file1.abc

It would take me a while to make this work, but maybe that's a starting
point for you.

Is this something you will want to do again later, or is it a one-time
operation?

  #11  
Old June 8th 17, 11:01 PM posted to alt.comp.os.windows-10
Philip Herlihy
external usenet poster
 
Posts: 208
Default Adding one line to a directory full of text files

In article ,
says...

I need to add a line to a directory full of text files with the same
extension (which isn't .txt but I don't know if that matters).

Is there an easy way in Windows 10 to run a command that does this?

Pseudocode:
If the file name ends in xxx and if the last line isn't "do this",
then add a line of "do this".

Alternatively, I can just blindly add "do this" to the end of all files
in the directory, since having the directive twice won't hurt anything.

Any suggestions for a simple way to do this for a non programmer?


I get it. You have a directory/folder full of script files (eg *.cmd or
*.bat). You want to modify each script so that it will run an
additional command at the end (if it's not there already).

Someone competent with DOS scripting could do this for you. If I wasn't
up to my ears in deadlines I'd write it for you.

The FOR command can run another command on each file.
The COPY command (using the + operator to append, and quoting a folder
as destination) will do the merge.
The FOR command may (I'm rusty!) be able to filter out files which
contain a specific string of characters, otherwise the FINDSTR command
can be incorporated.

If I had a spare hour (I'm rusty, remember!) to try this out, I'd send
you a tested script to do this. Someone else might be under less
pressure!

Rule 1: Work only on copies!

--

Phil, London
  #12  
Old June 8th 17, 11:39 PM posted to alt.comp.os.windows-10
NY
external usenet poster
 
Posts: 586
Default Adding one line to a directory full of text files

"Nil" wrote in message
...
On 08 Jun 2017, Chaya Eve wrote in
alt.comp.os.windows-10:

Notice that all I want to do is add "do this" to the end of every
file that is in a directory that ends with the filename extension
of "abc".

What's the easiest way to do that on Windows 10?


I'm sure you could put together a batch file that would step through a
directory of text files using the FOR and DO commands, and append
another text file ("DoThis.txt") to the end of each, the 2nd text file
contining only the line "do this" using the COPY command, like

COPY file1.abc+DoThis.txt file1.abc

It would take me a while to make this work, but maybe that's a starting
point for you.

Is this something you will want to do again later, or is it a one-time
operation?


Also "dir *abc.txt" will list the names of all txt files which end "abc" -
eg

fredabc.txt
abc.txt
f123abc.txt

but not

abc123.txt
asdf123dfg.txt

There should be a way of generating a FOR loop which processes each matching
file - I used to know this but it's late and I'm tired and I'm trying to
decide how much longer I can be bothered to stay up to watch the
Conservatives' rather underwhelming performance in the General Election here
in the UK. Bet Mrs May wishes she hadn't called the election...

  #13  
Old June 8th 17, 11:42 PM posted to alt.comp.os.windows-10
Nil[_5_]
external usenet poster
 
Posts: 1,731
Default Adding one line to a directory full of text files

On 08 Jun 2017, Nil wrote in
alt.comp.os.windows-10:

I'm sure you could put together a batch file that would step
through a directory of text files using the FOR and DO commands,
and append another text file ("DoThis.txt") to the end of each,
the 2nd text file contining only the line "do this" using the COPY
command, like

COPY file1.abc+DoThis.txt file1.abc

It would take me a while to make this work, but maybe that's a
starting point for you.

Is this something you will want to do again later, or is it a
one-time operation?


OK, this works for me. Put the batch file in the same directory as
the files. Make a backup of all the files in that directory until you're
sure it works as expected.

Not sure what the carat character is for, but it seems to be needed.

Put the below in a batch file (mine's called AddMoreText.cmd)

========= cut here =========

rem This will append a text file to some other files
rem Replace the variables FileSpec with the files
rem you want to receive the new text and AppendFile with
rem the name of a file containing the new text.

set FileSpec="file*.abc^"
set AppendFile="AddMe.txt"

FOR /F "tokens=*" %%G IN ('dir /b ^%FileSpec%') DO copy /b %%G+%AppendFile% %%G
  #14  
Old June 8th 17, 11:47 PM posted to alt.comp.os.windows-10
Chaya Eve
external usenet poster
 
Posts: 202
Default Adding one line to a directory full of text files

On Thu, 8 Jun 2017 23:01:26 +0100, Philip Herlihy
wrote:

I get it. You have a directory/folder full of script files (eg *.cmd or
*.bat). You want to modify each script so that it will run an
additional command at the end (if it's not there already).


This is the closest I found on the net so far, which I will try out:
https://stackoverflow.com/questions/...ows-batch-file

It's not exactly the same thing, so I will need to modify it.



@echo off
FOR /F %%C IN ('FIND /C /V "" ^%origfile%') DO SET totallines=%%C
set /a totallines+=1

@echo off
%origfile% (FOR /L %%i IN (1,1,%totallines%) DO (
SETLOCAL EnableDelayedExpansion
SET /p L=
IF %%i==%insertat% ECHO(!TL!
ECHO(!L!
ENDLOCAL
)
) %tempfile%

COPY /Y %tempfile% %origfile% NUL

DEL %tempfile%
  #15  
Old June 9th 17, 12:18 AM posted to alt.comp.os.windows-10
Machiel de Wit
external usenet poster
 
Posts: 73
Default Adding one line to a directory full of text files

Chaya Eve schreef op 08-06-2017
in :
I need to add a line to a directory full of text files with the same
extension (which isn't .txt but I don't know if that matters).

Is there an easy way in Windows 10 to run a command that does this?

Pseudocode:
If the file name ends in xxx and if the last line isn't "do this",
then add a line of "do this".

Alternatively, I can just blindly add "do this" to the end of all
files
in the directory, since having the directive twice won't hurt
anything.

Any suggestions for a simple way to do this for a non programmer?


Whith Notepad++ you can set a Makro and do auto completion.
https://notepad-plus-plus.org/
Ask the cummunity there.

--
MdW.
 




Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off






All times are GMT +1. The time now is 08:56 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 PCbanter.
The comments are property of their posters.