Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1 +1,11 @@
|
|||
{{omit from|Befunge|No filesystem support}}
|
||||
{{omit from|HTML}}
|
||||
{{omit from|Locomotive Basic|Does not have a real time clock.}}
|
||||
{{omit from|M4}}
|
||||
{{omit from|Maxima}}
|
||||
{{omit from|PARI/GP}}
|
||||
{{omit from|Retro}}
|
||||
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have a filesystem, just namespaced variables. -->
|
||||
{{omit from|ZX Spectrum Basic|Does not have a real time clock.}}
|
||||
{{task|File System Operations}}
|
||||
This task will attempt to get and set the modification time of a file.
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
---
|
||||
note: File System Operations
|
||||
category:
|
||||
- Date and time
|
||||
note: File modification time
|
||||
|
|
|
|||
34
Task/File-modification-time/AWK/file-modification-time.awk
Normal file
34
Task/File-modification-time/AWK/file-modification-time.awk
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/awk -f
|
||||
BEGIN { # file modification time on Unix, using stat
|
||||
fn ="input.txt"
|
||||
|
||||
cmd="stat " fn
|
||||
print "#", cmd
|
||||
system(cmd) # just execute cmd
|
||||
|
||||
cmd="stat -c %Y " fn # seconds since the epoch
|
||||
print "#", cmd
|
||||
system(cmd)
|
||||
|
||||
cmd="stat -c %y " fn # human-readable format
|
||||
print "#", cmd
|
||||
system(cmd)
|
||||
|
||||
print "##"
|
||||
cmd | getline x # get output from cmd
|
||||
#print x
|
||||
close(cmd)
|
||||
|
||||
n=split(x,stat," ")
|
||||
#for (i in stat) { print i, stat[i] }
|
||||
print "file:", fn
|
||||
print "date:", stat[1], "time:", stat[2]
|
||||
|
||||
### change filetime with touch:
|
||||
|
||||
cmd="touch -t 201409082359.59 " fn
|
||||
print "#", cmd; system(cmd)
|
||||
|
||||
cmd="stat " fn
|
||||
print "#", cmd; system(cmd)
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
(nth 5 (file-attributes "input.txt")) ;; mod date+time
|
||||
|
||||
(set-file-times "input.txt") ;; to current-time
|
||||
(set-file-times "input.txt"
|
||||
(encode-time 0 0 0 1 1 2014)) ;; to given date+time
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
;; print modification time
|
||||
(println (date (file-info "input.txt" 6)))
|
||||
|
||||
;; set modification time to now (Unix)
|
||||
(! "touch -m input.txt")
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
files #f, DefaultDir$ + "\*.*" ' all files in the defalt directory
|
||||
files #f, DefaultDir$ + "\*.*" ' all files in the default directory
|
||||
|
||||
print "hasanswer: ";#f HASANSWER() ' does it exist
|
||||
print "rowcount: ";#f ROWCOUNT() ' number of files in the directory
|
||||
|
|
@ -16,7 +16,7 @@ if #f hasanswer() then ' or loop with while #f hasansw
|
|||
print "isdir: ";#f ISDIR() ' is it a directory or file
|
||||
|
||||
name$ = #f NAME$()
|
||||
shell$("touch -t 201002032359.59 ";name$;""") ' sell to os to set date
|
||||
shell$("touch -t 201002032359.59 ";name$;""") ' shell to os to set date
|
||||
|
||||
print
|
||||
end if
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
import java.io.File
|
||||
import java.util.Date
|
||||
|
||||
object FileModificationTime extends App {
|
||||
def test(file: File) {
|
||||
val (t, init) = (file.lastModified(),
|
||||
s"The following ${if (file.isDirectory()) "directory" else "file"} called ${file.getPath()}")
|
||||
|
||||
println(init + (if (t == 0) " does not exist." else " was modified at " + new Date(t).toInstant()))
|
||||
println(init +
|
||||
(if (file.setLastModified(System.currentTimeMillis())) " was modified to current time." else " does not exist."))
|
||||
println(init +
|
||||
(if (file.setLastModified(t)) " was reset to previous time." else " does not exist."))
|
||||
}
|
||||
|
||||
// main
|
||||
List(new File("output.txt"), new File("docs")).foreach(test)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue