[Question] List for undetermined variables in file.. xP

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

[Question] List for undetermined variables in file.. xP

#1 Post by Ranguna173 » 07 Nov 2011 12:40

Hi!

Ok, the title is a "little" bit confusing.. (well, so is the question..)

I can't say what my question is, it's better to show you an example:

I have a file named "storebox.txt"
It contains the following lines:
C
M
D
--End of the file (this isn't part of the "storebox.txt")--

Now, there is a program that is always adding line to the storebox..
I need a code that would determinate how many lines there are in the text file and I need that code to copy all of them, I've been using this:

Code: Select all

> storebox.txt (
  set /p line1=
  set /p line2=
  set /p line3=
  )


But has I said, there is a program that adds line to the file, so there are more then 3 line in the file after the program modifies it.

Please help and thanks!

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: [Question] List for undetermined variables in file.. xP

#2 Post by Ranguna173 » 07 Nov 2011 14:42

No one?
Please..
I realy need this

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: [Question] List for undetermined variables in file.. xP

#3 Post by Ranguna173 » 07 Nov 2011 15:03

Thank you, but after some long hours googleing/googling I found the code, here is the code for those who want it:

Code: Select all

findstr /R /N "^" storebox.txt | find /C ":"


If you want to save the output in a variable then just save it in a file and load it:

Code: Select all

findstr /R /N "^" storebox.txt | find /C ":">count
< count (
  set /p line1=
  )


Now the variable "line1" contains the number of lines.

To copy the lines:

Code: Select all

findstr /R /N "^" storebox.txt | find /C ":">count
< count (
  set /p line1=
  )

if %line1%==3 goto copy3
if %line1%==4 goto copy4
if %line1%==5 goto copy5
if %line1%==6 goto copy6
if %line1%==7 goto copy7
if %line1%==8 goto copy8
if %line1%==9 goto copy9

:copy3
< storebox.txt (
  set /p line1=
  set /p line2=
  set /p line3=
  )

:copy4
< storebox.txt (
  set /p line1=
  set /p line2=
  set /p line3=
  set /p line4=
  )

:copy5
< storebox.txt (
  set /p line1=
  set /p line2=
  set /p line3=
  set /p line4=
  set /p line5=
  )

:copy6
< storebox.txt (
  set /p line1=
  set /p line2=
  set /p line3=
  set /p line4=
  set /p line5=
  set /p line6=
  )

:copy7
< storebox.txt (
  set /p line1=
  set /p line2=
  set /p line3=
  set /p line4=
  set /p line5=
  set /p line6=
  set /p line7=
  )

:copy8
< storebox.txt (
  set /p line1=
  set /p line2=
  set /p line3=
  set /p line4=
  set /p line5=
  set /p line6=
  set /p line7=
  set /p line8=
  )

:copy9
< storebox.txt (
  set /p line1=
  set /p line2=
  set /p line3=
  set /p line4=
  set /p line5=
  set /p line6=
  set /p line7=
  set /p line8=
  set /p line9=
  )

aGerman
Expert
Posts: 4705
Joined: 22 Jan 2010 18:01
Location: Germany

Re: [Question] List for undetermined variables in file.. xP

#4 Post by aGerman » 07 Nov 2011 15:34

Try

Code: Select all

@echo off &setlocal
for /f "tokens=2 delims=:" %%i in ('find /c /v "" "storebox.txt"') do (
  for /l %%j in (1 1 %%i) do (
    set /p "line%%j="
  )
)<"storebox.txt"

:: show the variables
set line

pause

But why do you need to store the lines in variables? Doesn't it make more sense to process the lines directly inside of the loop?

Regards
aGerman

Ranguna173
Posts: 104
Joined: 28 Jul 2011 17:32

Re: [Question] List for undetermined variables in file.. xP

#5 Post by Ranguna173 » 07 Nov 2011 15:51

aGerman wrote:Try

Code: Select all

@echo off &setlocal
for /f "tokens=2 delims=:" %%i in ('find /c /v "" "storebox.txt"') do (
  for /l %%j in (1 1 %%i) do (
    set /p "line%%j="
  )
)<"storebox.txt"

:: show the variables
set line

pause

But why do you need to store the lines in variables? Doesn't it make more sense to process the lines directly inside of the loop?

Regards
aGerman


Sorry, forgot to mention, I'm trying to not use the "for" command..
But thanks that worked, much smaller than mine, counts and saves...
Thank! I might use that! (in another batch)

Post Reply