Author Topic: list from TXT file  (Read 3314 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
list from TXT file
« on: May 24, 2005, 04:51:13 PM »
Hi all,

I'm trying to write a list in a TXT file ...
so i have this code...

Code: [Select]

(setq CBfullist (append fich_list fich_list2 R1x))
(setq CBAfile (open Cfile "w"))
(foreach n CBfullist
(write-line n CBAfile)
)  
(close CBAfile)


But not working..
i'm trying to not use the While command.

any help ?
Keep smile...

ronjonp

  • Needs a day job
  • Posts: 7533
list from TXT file
« Reply #1 on: May 24, 2005, 05:34:26 PM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Andrea

  • Water Moccasin
  • Posts: 2372
list from TXT file
« Reply #2 on: May 24, 2005, 05:52:22 PM »
ronjonp,

Thanks. but this can't help me..

I need to enter each item of a list ine a TXT file.
 :?
Keep smile...

Jeff_M

  • King Gator
  • Posts: 4100
  • C3D user & customizer
list from TXT file
« Reply #3 on: May 24, 2005, 06:15:14 PM »
What does your list look like?
("stuff" "more stuff") or (1 2 3 4) or ?

Andrea

  • Water Moccasin
  • Posts: 2372
list from TXT file
« Reply #4 on: May 24, 2005, 06:24:42 PM »
CBfullist = ("direct;7;777-777" "rm_sdb;7;XDF-ETG" "sh_spot;7;777-GFH" "chroma;7;XDF-ETR" "overhead;6;666-666")

and I need to put each of them in a txt file eg:

file 7.txt you will see:

direct;7;777-777
rm_sdb;7;XDF-ETG
sh_spot;7;777-GFH
chroma;7;XDF-ETR
overhead;6;666-666
Keep smile...

Jeff_M

  • King Gator
  • Posts: 4100
  • C3D user & customizer
list from TXT file
« Reply #5 on: May 24, 2005, 06:47:48 PM »
I suggest looking elswhere in your code for the error then. I just tried your list with the previous code, after setq'ing the filename, and it worked fine.

Andrea

  • Water Moccasin
  • Posts: 2372
list from TXT file
« Reply #6 on: May 25, 2005, 08:43:16 AM »
hmm....this is strange...

seem the file can't be close...
if i run this..(setq CBAfile (open Cfile "w"))
the response is ...nil.

so i have tried to rename the file manually to know if i can...and i can.
but if i try to delete this file...i can't.

i'm lost here. :cry:
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
list from TXT file
« Reply #7 on: May 25, 2005, 02:25:12 PM »
OK,,,i have found something wrong in this code..


Code: [Select]
(setq CBAfile (open Cfile "r"))
(repeat contlist
(read-line CBAfile)
)
  (close CBAfile)


I need to read the file from the first line to the 7th line from the file...Cfile
contlist = 7

this is working.....but the code can't close the file...why ?
Keep smile...

Jeff_M

  • King Gator
  • Posts: 4100
  • C3D user & customizer
list from TXT file
« Reply #8 on: May 25, 2005, 04:37:13 PM »
Andrea, could you post the entirety of your code? This works fine for me...using the file that the code in your first post created.
Code: [Select]

(setq cfile "c:\\test.txt"
      contlist 7)

(setq CBAfile (open Cfile "r"))
(repeat contlist
  (terpri)
  (princ (read-line CBAfile))
)
  (close CBAfile)

returns this in the VLIDE:
#<file "c:\\test.txt">
_$

direct;7;777-777
rm_sdb;7;XDF-ETG
sh_spot;7;777-GFH
chroma;7;XDF-ETR
overhead;6;666-666
nil
nil
nil
_$

nil
_$