comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Linux-like touch command in IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Linux-like touch command in IDL [message #90234 is a reply to message #90233] Thu, 12 February 2015 13:49 Go to previous messageGo to previous message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
Ok. Last reply. I found the Truncate_Lun procedure, so thought I would add another feature. For files, you can update ATIME only (by reading) or all three [ACM]TIME (by writing, then deleting). For directories, only the latter option is available.

----------------------------------


pro touch, path, $
ACCESS=access
on_error, 2

;Information about the path provided.
info = file_info(path)
if info.exists eq 0 then message, 'PATH does not exist: "' + path + '".'

;Defaults
access = keyword_set(access)
modify = ~access

;Directory
if info.directory then begin
;Modified Time (also updates Access and Status Change times)
if modify then begin
if info.write eq 0 then message, 'PATH must have write privileges.'

;Create a temporary file then delete it.
temp_file = filepath('touch_temp_file.txt', ROOT_DIR=path)
openw, lun, temp_file, /GET_LUN
free_lun, lun
file_delete, temp_file
endif else begin
message, 'The ACCESS option is not available for directories.'
endelse

;File
endif else begin
;Access Time
if access then begin
if info.read eq 0 then message, 'PATH must have read privileges.'

;Read one byte of data
var = 0B
openr, lun, path, /GET_LUN
readu, lun, var
free_lun, lun

;Modified Time (also updates Access and Status Change times)
endif else begin
if info.write eq 0 then message, 'PATH must have write privileges.'

;Open to the end of the file, and get the file position
openw, lun, path, /GET_LUN, /APPEND
point_lun, -lun, end_of_file

;Write one byte of data
writeu, lun, 0B

;Truncate the contents just written & close the file.
point_lun, lun, end_of_file
truncate_lun, lun
free_lun, lun

;Other
endelse
endelse
end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: EDG: Using IDL_MakeTempStruct() vs. IDL_ImportArray()
Next Topic: Variable attributes and undef vars

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:40:55 PDT 2025

Total time taken to generate the page: 0.00423 seconds