-2

I got something I'd really like to do (but am unable to by myself), for which I'm convinced batch is the right tool. I do however have a very superficial knowledge about it, so even though I don't really like to ask for it, I'm hereby asking for some kind minds among this community (or beyond) to make a program or part of it for me :s (for personal use only)
I'll certainly try to assemble together a program if components for it are shared, but I'm not expecting to be able to do so...
Among the research, I've found this link, which I guess is kinda useful...

The problem is as follows: I have 47 folders. Each folder has a different number of txt files. In total, there 10633 txt files, their names are mostly random.
I need to add 1 new line of text to all the txt files, ideally at the end of the files, but it can be in the first line, if easier.

From trial 'n error, it seems that I need to insert the new line, after the 3rd line of each txt file (aka 4th line)...

I've tried this code here with the only success being no ctd

 ::@echo off
setlocal enabledelayedexpansion
set num = 0

for /r %%a in (*.txt) do (
::pause ::debug
  for /f "tokens=*" %%a in (*.txt) do (
  if !num! lss 3 echo %%a >>tmp.txt
  if !num! equ 3 echo %%a >>tmp.txt
  if !num! gtr 3 echo.blablabla >>tmp.txt
  if !num! gtr 4 echo %%a >>tmp.txt
  set /a num+=1
  )
)
move /y tmp.txt *.txt

I can see that somethings not completely right with the code... since it doesn't completely work... , I just don't know what

Community
  • 1
  • 1
VLV
  • 167
  • 1
  • 12
  • You're getting downvotes because you posted a request for us to write code for you, showing absolutely no research effort or attempt to do anything yourself first. This is not a code writing service, where you post your requirements and someone churns out code for you. We expect you to do some work yourself, and use this site as a **last resort** to solve problems you encounter. – Ken White Sep 13 '14 at 01:23
  • lol, I did spend some 2-3 hours to find a way of modding a certain thing for some software, until I went for the solution of just editing all the data, thus the batch. I made some 20min of research on the batch, and seriously didn't feel like spending hours on batch when I know there are ppl like Monacraft who can do it much better and faster than myself. So, I'd really like to tell you some humungously nice words :) – VLV Sep 13 '14 at 01:44
  • but thanks for the comment anyway ^_^ – VLV Sep 13 '14 at 01:46
  • Sorry. You did ask why you were getting downvotes. "I made some 20min of research" is meaningless, and "didn't feel like spending hours" is an excuse for posting a "please do all my work for me because I'm too lazy" question. The fact that someone was (erroneously, IMO) nice enough to answer it doesn't change that fact. – Ken White Sep 13 '14 at 04:28
  • lol ffs, I wrote I spent hours on the damn thing, I can almost nothing of Batch but am aware of its capabilities, and know how often it happens that you need half a day to do something ridiculously simple if you do not know how to do it. Therefore, it's far more efficient to ask someone who knows it, since if you know it it takes something between half a minute to max one dozen. – VLV Sep 13 '14 at 08:06
  • @KenWhite Did you actually just downvote my answer :-( – Monacraft Sep 13 '14 at 11:29
  • @VLV Next time you write a question avoid the paragraphs of fluff and simply state your problem, the code you tried, the error you got, and any suggestions or ideas you think might work. – Monacraft Sep 13 '14 at 11:31
  • thanks, I don't usually write fluff, but since I didn't have any code at all... – VLV Sep 13 '14 at 12:34
  • @Monacraft: I downvoted this question (as well as voting to close it). While I don't think you should have answered it because of the low quality of the question, I did not vote on your answer. – Ken White Sep 13 '14 at 17:27
  • @KenWhite Well, I apologize for my ignorance, lack of Batch skill, knowledge and whatnot, and for asking stupid questions on the internet. Seriously though, I think it's a stupid waste of time to discuss this stuff lol. I asked for something and got a great answer, point. – VLV Sep 13 '14 at 18:29

1 Answers1

1

Try this bat file at the root folder for the 47 other folders. Note: it will effect all folders in this root folder and sub-folders.

Append.bat

@echo off
for /r %%a in (*.txt) do Echo.>> "%%a"

Which will append a new line to each *.txt within the folder tree

foxidrive
  • 40,353
  • 10
  • 53
  • 68
Monacraft
  • 6,510
  • 2
  • 17
  • 29
  • awesome, didn't expect it to be that simple ^_^ ty :) – VLV Sep 13 '14 at 01:37
  • edited the question instead of creating a new one, I'll leave your answer as the answer no matter what, but it'd be really awesome if you could help out again :) ? – VLV Sep 13 '14 at 02:34
  • @Monacraft can you explain `>> %%a` to me? – J-Dizzle Sep 13 '14 at 02:35
  • @VLV Open a new question to get further help. They are free. :) – foxidrive Sep 13 '14 at 07:49
  • @J-Dizzle In CMD using `>>` will append all output of a command to the specified file, where `"%%~a"` is that file. [Click here](http://www.robvanderwoude.com/redirection.php) for a full explanation on how to redirect in batch. – Monacraft Sep 13 '14 at 11:34