TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: xiaxiang on February 23, 2011, 02:14:20 AM
-
The next two issues to ask for advice.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Firstly, I want to use one lisp routine to remove specific text file in the specific path, for example:[ C:\WINDOWS\ d.ini ]. Perform this procedure, check whether the file in the path . If there are then delete it. Program is mainly used to kill a particular "as virus" file.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Secondly, it is more complex. I Want to get the system time with one lisp routine . But I should make it not so clearly, I just want to make a cover-up. Specific requirements are:
Perform this procedure, first check whether there is specified text file in a specific path , if there are not then creat it, for example:[ C:\WINDOWS\ d.ini ]. if there are Then skip this step. Get the System time and then write to the text file. The format of the time needs for requirements of 8 lines, 4 lines for Year numbers ,2 lines for Month numbers and 2 lines for Day numbers . The figures for each line is expressed as Decimal,use "49-58" to represent "0-9".
Format Example:
51 ----> 2
49 ----> 0
50 ----> 1
50 ----> 1
49 ----> 0
51 ----> 2
50 ----> 1
54 ----> 5
So very clear, the system time is February 15, 2011.
Waiting for your help! Greetings!
-
Hi,
For your first task, look at findfile and vl-file-delete functions.
For your second task, look at findfile, open, write-line and close functions.
To convert the date to ascii codes try:
(vl-string-to-list (menucmd "M=$(edtime, $(getvar,date),YYYY MO DD)"))
-
First, all you have to do is (vl-file-delete "C:\\Windows\\d.ini"). If the file is there, it will be deleted. If not, nothing happend.
For second part, use
(setq open_file (open "C:\\Windows\\d.ini" "w") )
This will open the file if is there; otherwise the file will be created.
To write current date in opened file
(setq a (substr (rtos (getvar "CDATE") 2 0) 1 8 ) )
(foreach n (vl-string->list a)
(princ n open_file)
(princ "\n" open_file)
)
(close open_file)
-
This (http://www.theswamp.org/index.php?topic=36877.msg418677#msg418677) may help as a reference for the DIESEL expression gile suggests.
-
Hi,
For your first task, look at findfile and vl-file-delete functions.
For your second task, look at findfile, open, write-line and close functions.
To convert the date to ascii codes try:
((menucmd "M=$(edtime, $(getvar,date),YYYY MO DD)"))
Hi,gile
Thanks for your help.I couldn't find "vl-string-to-list".Maybe "vl-string->list"?
-
First, all you have to do is (vl-file-delete "C:\\Windows\\d.ini"). If the file is there, it will be deleted. If not, nothing happend.
For second part, use
(setq open_file (open "C:\\Windows\\d.ini" "w") )
This will open the file if is there; otherwise the file will be created.
To write current date in opened file
(setq a (substr (rtos (getvar "CDATE") 2 0) 1 8 ) )
(foreach n (vl-string->list a)
(princ n open_file)
(princ "\n" open_file)
)
(close open_file)
Hi,phanaem
Thanks for helping me with your first post in the swamp.
I don't know why but the result which using your code is "50 48 49 49 48 50 50 52" for today.It's the Ascii Character codes.
It need to be offseted.So I add the Algorithm "+1" to your code. Then I get the result "51 49 50 50 49 51 51 53" just for today 20110224.That's what I need.
Then I post my code here.
(defun c:cs(/ X n open_file )
(setq open_file (open "C:\\Windows\\d.ini" "w") )
(setq a (substr (rtos (getvar "CDATE") 2 0) 1 8 ) )
;(foreach n (mapcar '(lambda (x) (+ x 1)) (vl-string->list a))
(foreach n (mapcar '1+ (vl-string->list a))
(princ n open_file)
(princ "\n" open_file)
)
(close open_file)
)
Thanks 8-)
-
This (http://www.theswamp.org/index.php?topic=36877.msg418677#msg418677) may help as a reference for the DIESEL expression gile suggests.
Thanks,Lee.The more we learn,the better we use.
-
Perhaps:
(mapcar '1+ (vl-string->list (menucmd "m=$(edtime,$(getvar,DATE),YYYYMODD)")))
-
Perhaps:
(mapcar '1+ (vl-string->list (menucmd "m=$(edtime,$(getvar,DATE),YYYYMODD)")))
Yes.It works well also.Thanks, Lee :-)