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. |
|
|
Thread Tools | Rate Thread | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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. |
#3
|
|||
|
|||
Adding one line to a directory full of text files
|
#4
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
Adding one line to a directory full of text files
|
#12
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 |
|
|