Author Topic: looking for suggestions on how to check txt file for changes  (Read 7753 times)

0 Members and 1 Guest are viewing this topic.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: looking for suggestions on how to check txt file for changes
« Reply #15 on: September 18, 2010, 10:41:19 AM »
You may want to look at McNeel's DOSLIB  ( dos_file )

http://wiki.mcneel.com/developer/doslib

VL knocked off quite a few of their functions, but I prefer their stuff.  My $0.02  -David
R12 Dos - A2K

BlackBox

  • King Gator
  • Posts: 3770
Re: looking for suggestions on how to check txt file for changes
« Reply #16 on: September 20, 2010, 09:23:19 AM »
Would "Wscript.shell" , or "Scripting.FileSystmeObject" also be able to extract the file's owner ID, perhaps? If so, that *may* lend to the OP's much needed comparison criteria.

I can't get (vlax-create-object "Scripting.FileSystmeObject") to work  :roll:

 :-D

Stupid Fat-Fingers! lol
"How we think determines what we do, and what we do determines what we get."

andrew_nao

  • Guest
Re: looking for suggestions on how to check txt file for changes
« Reply #17 on: September 20, 2010, 09:25:27 AM »
If its ok with the creators to modify their code a bit,
I think I can get something suitable for my needs

@ renderman your code isnt displaying the time


I appreciate everyones help

BlackBox

  • King Gator
  • Posts: 3770
Re: looking for suggestions on how to check txt file for changes
« Reply #18 on: September 20, 2010, 09:41:11 AM »
@ renderman your code isnt displaying the time

The reason it didn't work for you, is because this routine was only used for testing purposes (on my end), thus I used values that simplified my testing... Poor assumption on my part, I 'spose, assuming you'd know which lines of code to customize.

More specifically, please fill in your own values for the red text within the code:

Code: [Select]


(defun c:TEST  (/ filePath dateList hour)
  (vl-load-com)
  (terpri)
  (if (setq filePath
             (getfiled "Select a Text File"
                       "[color=red]Put_YourSearchFilePath_Here[/color]"
                       "[color=red]Put_TheFIleExtensionYouWant_Here[/color]" [color=green];; <- No preceding period[/color]                       
                       8))
    (princ
      (strcat
        "\n  >>  \""
        (strcase (vl-filename-base filepath))
        "\"  >>  Was Last Modified: "
        (itoa (car (setq dateList (vl-file-systime filePath))))
        "-"
        (itoa (cadr dateList))
        "-"
        (itoa (nth 3 dateList))
        ", at "
        (cond
          ((<= 12 (setq hour (nth 4 dateList)))
           ([color=blue]strcat[/color]
             (if (= 12 hour)
               (itoa hour)
               (itoa (- hour 12)))
             ":"
             (itoa (nth 5 dateList))
             " PM"))
          ((strcat (itoa hour) ":" (itoa (nth 5 dateList)) " AM"))))))
  (terpri)
  (princ))

Edit:  For additional information, please read the Developer Documentation regarding the getfiled function.
« Last Edit: September 20, 2010, 10:33:40 AM by RenderMan »
"How we think determines what we do, and what we do determines what we get."

andrew_nao

  • Guest
Re: looking for suggestions on how to check txt file for changes
« Reply #19 on: September 20, 2010, 10:22:02 AM »
pardon my ignorance for not being more detailed in the error, Renderman
while your help is greatly appreciated

this is what is displaying
>>  "PARTS"  >>  Was Last Modified: 9-17-2010, at  PM

its not displaying the PM time.
Code: [Select]
         (cond
          (
           (<= 12 (setq hour (nth 4 dateList)))
           (progn
             (if (= 12 hour)
               (itoa hour)
               (strcat (itoa (- hour 12))
                ":"
               (itoa (nth 5 dateList))
                " PM")
             )
           )
          )
          ((strcat (itoa hour) ":" (itoa (nth 5 dateList)) " AM"

if i run just the code snippet above, it displays correctly
if i edit the original code with the above snippet, it doesnt work

the cond statements always confuse me, so im still pluggin at it but this is definitly where the issue is

thanks again

BlackBox

  • King Gator
  • Posts: 3770
Re: looking for suggestions on how to check txt file for changes
« Reply #20 on: September 20, 2010, 10:35:48 AM »
pardon my ignorance for not being more detailed in the error, Renderman
while your help is greatly appreciated

this is what is displaying
>>  "PARTS"  >>  Was Last Modified: 9-17-2010, at  PM

its not displaying the PM time.

Please forgive *my* fat fingers... I incorrectly added a progn, in lieu of a strcat... note the blue correction in my above posted code.

Hope this helps!
"How we think determines what we do, and what we do determines what we get."

andrew_nao

  • Guest
Re: looking for suggestions on how to check txt file for changes
« Reply #21 on: September 20, 2010, 11:11:43 AM »
its always good to have an extra pair of eyes
 :-o

thank you for your help

BlackBox

  • King Gator
  • Posts: 3770
Re: looking for suggestions on how to check txt file for changes
« Reply #22 on: September 20, 2010, 12:53:12 PM »
its always good to have an extra pair of eyes
 :-o

thank you for your help

You're welcome. Glad I could offer a lil' help.  :wink:
"How we think determines what we do, and what we do determines what we get."

andrew_nao

  • Guest
Re: looking for suggestions on how to check txt file for changes
« Reply #23 on: September 23, 2010, 10:08:30 AM »
ok new situation,
using the following code (thanks again for the help)
i have the code reading a line in a text file in order to compare the time the file has been modified last and then it writes the new time back to the text file for comparison the next time its modified.
I have 5 stations that need to run this lisp to let them know of any changes
if one station runs the lisp it writes back to the text file the last time the file was changed and therefore the next station who runs this lisp wont know of the changes.
which brings me to the next question.
does anyone have an idea on how i can get this to run on 5 stations without writing back untill ever station that is turned on, has ran it?
i thought of using the getvar loginname function and setting it for after i run it, it writes back, but lets say if im on vacation or out of the day, how could it write back when its just say 3 stations operating?

any thoughts are appreciated

here is the code
Code: [Select]
(defun c:stkchkfile  (/ filePath dateList hour cmdecho check_file_time check_file) ;filePath dateList hour

;;******* check for user data file last recorded modification time
(defun readfile (filename / f path line lst) ;f path line lst
(setq user_data_file (findfile "acad_user_data.txt"))
  (if (setq path user_data_file)
    (cond
      ((setq f (open path "r"))
       (while (setq line (read-line f))
(setq lst (cons line lst))
       )
       (close f)
       (reverse lst)
      )
    ) ; end cond
  ) ; end if
) ; end defun



;;*********** check for stock file modification date and time
  (terpri)
  (if (setq filePath "F:/stock/partdes.txt")
    (setq check_file
      (strcat
        "Stock book was last modified on: "
        (itoa (cadr (setq dateList (vl-file-systime filePath))))
        "-"
        (itoa (nth 3 dateList))
        "-"
        (itoa (car dateList))
        ", at "
        (cond
          ((<= 12 (setq hour (nth 4 dateList)))
           (strcat
             (if (= 12 hour)
               (itoa hour)
               (itoa (- hour 12))
             )
                ":"
               (itoa (nth 5 dateList))
               " PM")
           )
          ((strcat (itoa hour) ":" (itoa (nth 5 dateList)) " AM"))
        ) ; end cond
        "\n Please check your part numbers"
      ) ; end strcat
    ) ; end setq
  )  ; end if

(setq check_file_time
         (cond
          ((<= 12 (setq hour (nth 4 dateList)))
           (strcat
             (if (= 12 hour)
               (itoa hour)
               (itoa (- hour 12))
             )
               ":"
               (itoa (nth 5 dateList))
               " PM"
           )
          )
          ((strcat (itoa hour) ":" (itoa (nth 5 dateList)) " AM")))
)

  (terpri)
  (princ)



;;********* send alert if file has been modified

;; Ensure OpenDCL Runtime is (quietly) loaded
(setq cmdecho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(command "_OPENDCL")
(setvar "CMDECHO" cmdecho)


; call the method to load the odcl file.
(dcl_Project_Load "stkfilecheck" T)

(if (setq lst (readfile user_data_file))
(setq last_mod (nth 0 lst))
)

(if (/= check_file_time last_mod)
 (dcl_MessageBox check_file "Stockbook file checker" 2 1)
)


;;******** write back new modification time

(SETQ last_mod (SUBST check_file_time (NTH 0 lst) lst))
(SETQ m_file user_data_file)
(setq o_file (open m_file "w"))
(write-line (nth 0 last_mod) o_file)
(close o_file)

  (terpri)
  (princ)

) ;end



andrew_nao

  • Guest
Re: looking for suggestions on how to check txt file for changes
« Reply #24 on: September 23, 2010, 03:51:08 PM »
I think I solved my issue

i just copied the file that is written to on the local machine so each station has its own file to compare to instead of 1 file on the network

but i would still like to hear other peoples ideas if you have any