Something error about file write function

Q&A's, tips, howto's
Locked
winger
Posts: 46
Joined: Wed Mar 14, 2012 7:31 am

Something error about file write function

Post by winger »

Today I write a Script to download newlisp's benchmark code.
But I Can't find file in my directory.
I was scared! It been eat ! OMG

Code: Select all

(set 'page (get-url "http://www.newlisp.org/benchmarks/"))
(set 'files (find-all {(syntax\.cgi\?benchmarks/.*newlisp\.txt)\"} page $1)) ;ye , this is error filename, so suk!
(println files)
(dolist (file files)
  (write-file (string "./"file)
  (get-url (string "http://www.newlisp.org/" file)))
  (println "->" file))

(exit)
Last edited by winger on Mon Jun 04, 2012 10:42 am, edited 2 times in total.
Welcome to a newlisper home:)
http://www.cngrayhat.org

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Something error about file write function

Post by Lutz »

When you use syntax.cgi? in the URL you will get all the HTML too and ? is not allowed in file names. To get the raw text files:

Code: Select all

(set 'page (get-url "http://www.newlisp.org/benchmarks/"))
(set 'files (find-all {(syntax\.cgi\?benchmarks/.*newlisp\.txt)\"} page $1))
(println files)
(dolist (file files)
  (set 'file (last (parse file "/")))
  (write-file file (get-url (string "http://www.newlisp.org/benchmarks/" file)))
  (println "->" file))

(exit)

winger
Posts: 46
Joined: Wed Mar 14, 2012 7:31 am

Re: Something error about file write function

Post by winger »

Yes .
You'are right.
In my opinion it should throw a waring message when filename is incorrect.
Though we can use (true? filename) determine whether filename is correct.
Welcome to a newlisper home:)
http://www.cngrayhat.org

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Something error about file write function

Post by Lutz »

Like other file I/O functions in newLISP write-file will return nil on failure. You can then use sys-error to find out the error.

ps: this has been added to the reference manual.

Locked