Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: New Line In File  (Read 6882 times)

0 Members and 1 Guest are viewing this topic.

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: New Line In File
« Reply #15 on: January 19, 2009, 02:31:19 PM »
Did you set fname variable to the label of a file on your system?

Quote
Tried the script...Just echos %fname% then closes

There is no echo %fname% instruction in the script. I'm as surprised as you!

Quote
but for a secret that has to remain vetween my friend and I, I can't reveal the complete reason why I actually need each line as a variable (one reason that I'm allowed to talk about is what I said before, my other script gets jumpy).

<sigh> Still compressing/decompressing files?

The first block of the script count the records in  the file

The second block subtracts 30 from the recordcount and either loads the array from the file (recordcount - 30 is negative) or skips recordcount - 30 records before loading the array

The third block lists out the contents of the array

I can't duplicate your error. There may have been an error when you copied/pasted the code into your editor.

 8)

Batch code does cloak and dagger. Who knew?

I'll try the code again...But no, it is not compressing then decompressing files.

But, like I said, the complete reason why I need this must remain between my friend and I, although to help you I will say this:

I need to be able to remove a certain line at will (or automatically if its the first line and there are 31 lines) without directly modifying the text file.

Dias, I was asking for help, not for wasting comments.


EDIT: Code works...almost. It will echo each and every line, and if there is more than 30, doesn't show the first lines...but how can I get each visible line as a variable???
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: New Line In File
« Reply #16 on: January 19, 2009, 04:12:18 PM »
Quote
EDIT: Code works...almost. It will echo each and every line, and if there is more than 30, doesn't show the first lines...but how can I get each visible line as a variable???

It could be me, but isn't this what you asked for?

Quote
1. I'm trying to get the contents, and set each line as a variable.
2. If the linecount exceeds a certain amount (30 for example) delete the first line and move everything up a line.

If you want all the lines in variables remove some of the logic from the posted code:

Code: [Select]
@echo off
setlocal
set fname=drive:\path\file.ext

for /f "tokens=* delims=" %%x in (%fname%) do (
call set /a idx=%%idx%%+1
call set array.%%idx%%=%%x
)

for /l %%x in (1,1,%idx%) do call echo %%array.%%x%%

Be aware the environment space (where your variables are stored) is limited to 8K bytes on a XP machine.

Quote
I need to be able to remove a certain line at will (or automatically if its the first line and there are 31 lines) without directly modifying the text file.

Determine which line to delete and write out a new file. You don't need a variable for each line, you need a counter. By the way who is Will?

 8)

Perhaps you should get together with the other guy on this board with the 142 labels. You could share the cost of a KISS 101 course :o
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: New Line In File
« Reply #17 on: January 20, 2009, 12:36:11 AM »
Quote
Hamlet? 0x2B | ~ 0x2B
Yes. Hamlet was not a programmer. In the original context it was an XOR that had to have a YES or NO. But the C construct would become -1  if converted directly to a number. What would Hamlet think if we told him the answer is always minus one?

Dias de verano

  • Guest
Re: New Line In File
« Reply #18 on: January 20, 2009, 12:46:54 AM »
Quote
You don't need a variable for each line, you need a counter.

I told him this days ago.

Helpmeh

    Topic Starter


    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: New Line In File
« Reply #19 on: January 20, 2009, 04:09:03 PM »
Quote
You don't need a variable for each line, you need a counter.

I told him this days ago.
And I said that I DO need a variable for each line. (But atleast my problem is partially done)
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.