Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
category:
- Date and time
from: http://rosettacode.org/wiki/File_modification_time
note: File modification time|File System Operations

View file

@ -0,0 +1,4 @@
;Task:
Get and set the modification time of a file.
<br><br>

View file

@ -0,0 +1,10 @@
PROC get output = (STRING cmd) VOID:
IF STRING sh cmd = " " + cmd + " ; 2>&1";
STRING output;
execve output ("/bin/sh", ("sh", "-c", sh cmd), "", output) >= 0
THEN print (output) FI;
get output ("rm -rf WTC_1"); CO Ensure file doesn't exist CO
get output ("touch WTC_1"); CO Create file CO
get output ("ls -l --time-style=full-iso WTC_1"); CO Display its last modified time CO
get output ("touch -t 200109111246.40 WTC_1"); CO Change its last modified time CO
get output ("ls -l --time-style=full-iso WTC_1") CO Verify it changed CO

View file

@ -0,0 +1,15 @@
@load "filefuncs"
BEGIN {
name = "input.txt"
# display time
stat(name, fd)
printf("%s\t%s\n", name, strftime("%a %b %e %H:%M:%S %Z %Y", fd["mtime"]) )
# change time
cmd = "touch -t 201409082359.59 " name
system(cmd)
close(cmd)
}

View 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)
}

View file

@ -0,0 +1,8 @@
with Ada.Directories; use Ada.Directories;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
procedure File_Time_Test is
begin
Put_Line (Image (Modification_Time ("file_time_test.adb")));
end File_Time_Test;

View file

@ -0,0 +1,5 @@
FileGetTime, OutputVar, output.txt
MsgBox % OutputVar
FileSetTime, 20080101, output.txt
FileGetTime, OutputVar, output.txt
MsgBox % OutputVar

View file

@ -0,0 +1,27 @@
DIM ft{dwLowDateTime%, dwHighDateTime%}
DIM st{wYear{l&,h&}, wMonth{l&,h&}, wDayOfWeek{l&,h&}, \
\ wDay{l&,h&}, wHour{l&,h&}, wMinute{l&,h&}, \
\ wSecond{l&,h&}, wMilliseconds{l&,h&} }
REM File is assumed to exist:
file$ = @tmp$ + "rosetta.tmp"
REM Get and display the modification time:
file% = OPENIN(file$)
SYS "GetFileTime", @hfile%(file%), 0, 0, ft{}
CLOSE #file%
SYS "FileTimeToSystemTime", ft{}, st{}
date$ = STRING$(16, CHR$0)
time$ = STRING$(16, CHR$0)
SYS "GetDateFormat", 0, 0, st{}, 0, date$, LEN(date$) TO N%
date$ = LEFT$(date$, N%-1)
SYS "GetTimeFormat", 0, 0, st{}, 0, time$, LEN(time$) TO N%
time$ = LEFT$(time$, N%-1)
PRINT date$ " " time$
REM Set the modification time to the current time:
SYS "GetSystemTime", st{}
SYS "SystemTimeToFileTime", st{}, ft{}
file% = OPENUP(file$)
SYS "SetFileTime", @hfile%(file%), 0, 0, ft{}
CLOSE #file%

View file

@ -0,0 +1 @@
for %%f in (file.txt) do echo.%%~tf

View file

@ -0,0 +1,25 @@
#include <boost/filesystem/operations.hpp>
#include <ctime>
#include <iostream>
int main( int argc , char *argv[ ] ) {
if ( argc != 2 ) {
std::cerr << "Error! Syntax: moditime <filename>!\n" ;
return 1 ;
}
boost::filesystem::path p( argv[ 1 ] ) ;
if ( boost::filesystem::exists( p ) ) {
std::time_t t = boost::filesystem::last_write_time( p ) ;
std::cout << "On " << std::ctime( &t ) << " the file " << argv[ 1 ]
<< " was modified the last time!\n" ;
std::cout << "Setting the modification time to now:\n" ;
std::time_t n = std::time( 0 ) ;
boost::filesystem::last_write_time( p , n ) ;
t = boost::filesystem::last_write_time( p ) ;
std::cout << "Now the modification time is " << std::ctime( &t ) << std::endl ;
return 0 ;
} else {
std::cout << "Could not find file " << argv[ 1 ] << '\n' ;
return 2 ;
}
}

View file

@ -0,0 +1,5 @@
using System;
using System.IO;
Console.WriteLine(File.GetLastWriteTime("file.txt"));
File.SetLastWriteTime("file.txt", DateTime.Now);

View file

@ -0,0 +1,27 @@
#include <sys/stat.h>
#include <stdio.h>
#include <time.h>
#include <utime.h>
const char *filename = "input.txt";
int main() {
struct stat foo;
time_t mtime;
struct utimbuf new_times;
if (stat(filename, &foo) < 0) {
perror(filename);
return 1;
}
mtime = foo.st_mtime; /* seconds since the epoch */
new_times.actime = foo.st_atime; /* keep atime unchanged */
new_times.modtime = time(NULL); /* set mtime to current time */
if (utime(filename, &new_times) < 0) {
perror(filename);
return 1;
}
return 0;
}

View file

@ -0,0 +1,24 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <err.h>
const char *filename = "input.txt";
int main() {
struct stat foo;
struct timeval new_times[2];
if (stat(filename, &foo) < 0)
err(1, "%s", filename);
/* keep atime unchanged */
TIMESPEC_TO_TIMEVAL(&new_times[0], &foo.st_atim);
/* set mtime to current time */
gettimeofday(&new_times[1], NULL);
if (utimes(filename, new_times) < 0)
err(1, "%s", filename);
return 0;
}

View file

@ -0,0 +1,30 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <time.h>
#include <fcntl.h>
#include <stdio.h>
const char *filename = "input.txt";
int main() {
struct stat foo;
struct timespec new_times[2];
if (stat(filename, &foo) < 0) {
perror(filename);
return 1;
}
/* keep atime unchanged */
new_times[0] = foo.st_atim;
/* set mtime to current time */
clock_gettime(CLOCK_REALTIME, &new_times[1]);
if (utimensat(AT_FDCWD, filename, new_times, 0) < 0) {
perror(filename);
return 1;
}
return 0;
}

View file

@ -0,0 +1,107 @@
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
/* Print "message: last Win32 error" to stderr. */
void
oops(const wchar_t *message)
{
wchar_t *buf;
DWORD error;
buf = NULL;
error = GetLastError();
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, error, 0, (wchar_t *)&buf, 0, NULL);
if (buf) {
fwprintf(stderr, L"%ls: %ls", message, buf);
LocalFree(buf);
} else {
/* FormatMessageW failed. */
fwprintf(stderr, L"%ls: unknown error 0x%x\n",
message, error);
}
}
int
setmodtime(const wchar_t *path)
{
FILETIME modtime;
SYSTEMTIME st;
HANDLE fh;
wchar_t date[80], time[80];
fh = CreateFileW(path, GENERIC_READ | FILE_WRITE_ATTRIBUTES,
0, NULL, OPEN_EXISTING, 0, NULL);
if (fh == INVALID_HANDLE_VALUE) {
oops(path);
return 1;
}
/*
* Use GetFileTime() to get the file modification time.
*/
if (GetFileTime(fh, NULL, NULL, &modtime) == 0)
goto fail;
FileTimeToSystemTime(&modtime, &st);
if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL,
date, sizeof date / sizeof date[0]) == 0 ||
GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL,
time, sizeof time / sizeof time[0]) == 0)
goto fail;
wprintf(L"%ls: Last modified at %s at %s (UTC).\n",
path, date, time);
/*
* Use SetFileTime() to change the file modification time
* to the current time.
*/
GetSystemTime(&st);
if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL,
date, sizeof date / sizeof date[0]) == 0 ||
GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL,
time, sizeof time / sizeof time[0]) == 0)
goto fail;
SystemTimeToFileTime(&st, &modtime);
if (SetFileTime(fh, NULL, NULL, &modtime) == 0)
goto fail;
wprintf(L"%ls: Changed to %s at %s (UTC).\n", path, date, time);
CloseHandle(fh);
return 0;
fail:
oops(path);
CloseHandle(fh);
return 1;
}
/*
* Show the file modification time, and change it to the current time.
*/
int
main()
{
int argc, i, r;
wchar_t **argv;
/* MinGW never provides wmain(argc, argv). */
argv = CommandLineToArgvW(GetCommandLineW(), &argc);
if (argv == NULL) {
oops(L"CommandLineToArgvW");
exit(1);
}
if (argc < 2) {
fwprintf(stderr, L"usage: %ls file...\n", argv[0]);
exit(1);
}
r = 0;
for (i = 1; argv[i] != NULL; i++)
if (setmodtime(argv[i])) r = 1;
return r;
}

View file

@ -0,0 +1,8 @@
(import '(java.io File)
'(java.util Date))
(Date. (.lastModified (File. "output.txt")))
(Date. (.lastModified (File. "docs")))
(.setLastModified (File. "output.txt")
(.lastModified (File. "docs")))

View file

@ -0,0 +1 @@
(file-write-date "input.txt")

View file

@ -0,0 +1,6 @@
(let* ((filename "input.txt")
(stat (sb-posix:stat filename))
(mtime (sb-posix:stat-mtime stat)))
(sb-posix:utime filename
(sb-posix:stat-atime stat)
(sb-posix:time)))

View file

@ -0,0 +1,10 @@
import std.stdio;
import std.file: getTimes, setTimes, SysTime;
void main() {
auto fname = "unixdict.txt";
SysTime fileAccessTime, fileModificationTime;
getTimes(fname, fileAccessTime, fileModificationTime);
writeln(fileAccessTime, "\n", fileModificationTime);
setTimes(fname, fileAccessTime, fileModificationTime);
}

View file

@ -0,0 +1,16 @@
function GetModifiedDate(const aFilename: string): TDateTime;
var
hFile: Integer;
iDosTime: Integer;
begin
hFile := FileOpen(aFilename, fmOpenRead);
iDosTime := FileGetDate(hFile);
FileClose(hFile);
if (hFile = -1) or (iDosTime = -1) then raise Exception.Create('Cannot read file: ' + sFilename);
Result := FileDateToDateTime(iDosTime);
end;
procedure ChangeModifiedDate(const aFilename: string; aDateTime: TDateTime);
begin
FileSetDate(aFileName, DateTimeToFileDate(aDateTime));
end;

View file

@ -0,0 +1,16 @@
def strdate(date) {
return E.toString(<unsafe:java.util.makeDate>(date))
}
def test(type, file) {
def t := file.lastModified()
println(`The following $type called ${file.getPath()} ${
if (t == 0) { "does not exist." } else { `was modified at ${strdate(t)}` }}`)
println(`The following $type called ${file.getPath()} ${
escape ne { file.setLastModified(timer.now(), ne); "was modified to current time." } catch _ { "does not exist." }}`)
println(`The following $type called ${file.getPath()} ${
escape ne { file.setLastModified(t, ne); "was modified to previous time." } catch _ { "does not exist." }}`)
}
test("file", <file:output.txt>)
test("directory", <file:docs>)

View file

@ -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

View file

@ -0,0 +1,11 @@
-module( file_modification_time ).
-include_lib("kernel/include/file.hrl").
-export( [task/0] ).
task() ->
File = "input.txt",
{ok, File_info} = file:read_file_info( File ),
io:fwrite( "Modification time ~p~n", [File_info#file_info.mtime] ),
ok = file:write_file_info( File, File_info#file_info{mtime=calendar:local_time()} ).

View file

@ -0,0 +1,8 @@
open System
open System.IO
[<EntryPoint>]
let main args =
Console.WriteLine(File.GetLastWriteTime(args.[0]))
File.SetLastWriteTime(args.[0], DateTime.Now)
0

View file

@ -0,0 +1 @@
"foo.txt" file-info modified>> .

View file

@ -0,0 +1,3 @@
USE: io.files.info.unix
"foo.txt" now 2 hours time+ set-file-modified-time

View file

@ -0,0 +1,20 @@
' FB 1.05.0 Win64
' This example is taken directly from the FB documentation (see [http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgFiledatetime])
#include "vbcompat.bi" '' to use Format function
Dim filename As String, d As Double
Print "Enter a filename: "
Line Input filename
If FileExists(filename) Then
Print "File last modified: ";
d = FileDateTime( filename )
Print Format( d, "yyyy-mm-dd hh:mm AM/PM" )
Else
Print "File not found"
End If
Sleep

View file

@ -0,0 +1,4 @@
f = newJava["java.io.File", "FileModificationTime.frink"]
epoch = #1970 UTC#
f.setLastModified[(#2022-01-01 5:00 AM# - epoch) / ms]
println[f.lastModified[] ms + epoch]

View file

@ -0,0 +1 @@
Start,My Documents,Rightclick:Icon:Foobar.txt,Properties

View file

@ -0,0 +1,9 @@
' There is no built in command in Gambas to 'set' the modification time of a file
' A shell call to 'touch' would do it
Public Sub Main()
Dim stInfo As Stat = Stat(User.home &/ "Rosetta.txt")
Print "Rosetta.txt was last modified " & Format(stInfo.LastModified, "dd/mm/yyy hh:nn:ss")
End

View file

@ -0,0 +1,27 @@
package main
import (
"fmt"
"os"
"syscall"
"time"
)
var filename = "input.txt"
func main() {
foo, err := os.Stat(filename)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("mod time was:", foo.ModTime())
mtime := time.Now()
atime := mtime // a default, because os.Chtimes has an atime parameter.
// but see if there's a real atime that we can preserve.
if ss, ok := foo.Sys().(*syscall.Stat_t); ok {
atime = time.Unix(ss.Atim.Sec, ss.Atim.Nsec)
}
os.Chtimes(filename, atime, mtime)
fmt.Println("mod time now:", mtime)
}

View file

@ -0,0 +1,9 @@
import System.Posix.Files
import System.Posix.Time
do status <- getFileStatus filename
let atime = accessTime status
mtime = modificationTime status -- seconds since the epoch
curTime <- epochTime
setFileTimes filename atime curTime -- keep atime unchanged
-- set mtime to current time

View file

@ -0,0 +1,6 @@
import System.Directory
import System.Time
do ct <- getModificationTime filename
cal <- toCalendarTime ct
putStrLn (calendarTimeToString cal)

View file

@ -0,0 +1,7 @@
CHARACTER timestamp*18
timestamp = ' ' ! blank timestamp will read:
SYSTEM(FIle="File_modification_time.hic", FileTime=timestamp) ! 20100320141940.525
timestamp = '19991231235950' ! set timestamp to Millenium - 10 seconds
SYSTEM(FIle="File_modification_time.hic", FileTime=timestamp)

View file

@ -0,0 +1,9 @@
every dir := !["./","/"] do {
if i := stat(f := dir || "input.txt") then {
write("info for ",f ," mtime= ",ctime(i.mtime),", atime=",ctime(i.ctime), ", atime=",ctime(i.atime))
utime(f,i.atime,i.mtime-1024)
i := stat(f)
write("update for ",f ," mtime= ",ctime(i.mtime),", atime=",ctime(i.ctime), ", atime=",ctime(i.atime))
}
else stop("failure to stat ",f)
}

View file

@ -0,0 +1,3 @@
load 'files'
fstamp 'input.txt'
2009 8 24 20 34 30

View file

@ -0,0 +1,8 @@
public static void main(String[] args) {
File file = new File("file.txt");
/* get */
/* returns '0' if the file does not exist */
System.out.printf("%tD %1$tT%n", file.lastModified());
/* set */
file.setLastModified(System.currentTimeMillis());
}

View file

@ -0,0 +1,20 @@
import java.io.File;
import java.util.Date;
public class FileModificationTimeTest {
public static void test(String type, File file) {
long t = file.lastModified();
System.out.println("The following " + type + " called " + file.getPath() +
(t == 0 ? " does not exist." : " was modified at " + new Date(t).toString() )
);
System.out.println("The following " + type + " called " + file.getPath() +
(!file.setLastModified(System.currentTimeMillis()) ? " does not exist." : " was modified to current time." )
);
System.out.println("The following " + type + " called " + file.getPath() +
(!file.setLastModified(t) ? " does not exist." : " was modified to previous time." )
);
}
public static void main(String args[]) {
test("file", new File("output.txt"));
test("directory", new File("docs"));
}
}

View file

@ -0,0 +1,3 @@
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.GetFile('input.txt');
var mtime = f.DateLastModified;

View file

@ -0,0 +1,2 @@
var file = document.getElementById("fileInput").files.item(0);
var last_modified = file.lastModifiedDate;

View file

@ -0,0 +1,9 @@
/* File modification times, in Jsi */
var fileTime = File.mtime('fileModificationTime.jsi');
puts("Last mod time was: ", strftime(fileTime * 1000));
exec('touch fileModificationTime.jsi');
fileTime = File.mtime('fileModificationTime.jsi');
puts("Mod time now: ", strftime(fileTime * 1000));

View file

@ -0,0 +1,8 @@
using Dates
fname, _ = mktemp()
println("The modification time of $fname is ", Dates.unix2datetime(mtime(fname)))
println("\nTouch this file.")
touch(fname)
println("The modification time of $fname is now ", Dates.unix2datetime(mtime(fname)))

View file

@ -0,0 +1,14 @@
// version 1.0.6
import java.io.File
fun main(args: Array<String>) {
val filePath = "input.txt" // or whatever
val file = File(filePath)
with (file) {
println("%tc".format(lastModified()))
// update to current time, say
setLastModified(System.currentTimeMillis())
println("%tc".format(lastModified()))
}
}

View file

@ -0,0 +1,15 @@
# Load the IO module
# Replace "<pathToIO.lm>" with the location where the io.lm Lang module was installed to without "<" and ">"
ln.loadModule(<pathToIO.lm>)
$file = [[io]]::fp.openFile(input.txt)
$modTime = [[io]]::fp.getModificationDate($file)
fn.println(Mod Time: $modTime)
[[io]]::fp.setModificationDate($file, fn.currentTimeMillis())
$modTime = [[io]]::fp.getModificationDate($file)
fn.println(Mod Time now: $modTime)
[[io]]::fp.closeFile($file)

View file

@ -0,0 +1,4 @@
local(f) = file('input.txt')
handle => { #f->close }
#f->modificationDate->format('%-D %r')
// result: 12/2/2010 11:04:15 PM

View file

@ -0,0 +1,13 @@
require "lfs"
local attributes = lfs.attributes("input.txt")
if attributes then
print(path .. " was last modified " .. os.date("%c", attributes.modification) .. ".")
-- set access and modification time to now ...
lfs.touch("input.txt")
-- ... or set modification time to now, keep original access time
lfs.touch("input.txt", attributes.access, os.time())
else
print(path .. " does not exist.")
end

View file

@ -0,0 +1,16 @@
Module CheckIt {
\\ without *for wide output* we open for ANSI (1 byte per character)
\\ but here we need it only for the creation of a file
Open "afile" for output as #f
Close #f
Print file.stamp("afile") 'it is a number in VB6 date format.
date k=file.stamp("afile", -2) // Version 12 has date type, convert number or string to date type
print k // this has type date but print as string using default system locale date and time format
\\ day format as for Greece
Print Str$(File.Stamp("afile"),"hh:nn:ss dd/mm/yyyy") , "utc write time - by default"
Print Str$(File.Stamp("afile" ,1),"hh:nn:ss dd/mm/yyyy") , "utc write time, 1"
Print Str$(File.Stamp("afile" ,-1),"hh:nn:ss dd/mm/yyyy"), "local write time, -1"
Print Str$(File.Stamp("afile" ,2),"hh:nn:ss dd/mm/yyyy"), "utc creation time, 2"
Print Str$(File.Stamp("afile" ,-2),"hh:nn:ss dd/mm/yyyy"), "local creation time, -2"
}
Checkit

View file

@ -0,0 +1,5 @@
f = dir('output.txt'); % struct f contains file information
f.date % is string containing modification time
f.datenum % numerical format (number of days)
datestr(f.datenum) % is the same as f.date
% see also: stat, lstat

View file

@ -0,0 +1 @@
system('touch -t 201002032359.59 output.txt');

View file

@ -0,0 +1,2 @@
-- Returns a string containing the mod date for the file, e.g. "1/29/99 1:52:05 PM"
getFileModDate "C:\myFile.txt"

View file

@ -0,0 +1 @@
FileDate["file","Modification"]

View file

@ -0,0 +1 @@
SetFileDate["file",date,"Modification"]

View file

@ -0,0 +1,27 @@
MODULE ModTime EXPORTS Main;
IMPORT IO, Fmt, File, FS, Date, OSError;
TYPE dateArray = ARRAY [0..5] OF TEXT;
VAR
file: File.Status;
date: Date.T;
PROCEDURE DateArray(date: Date.T): dateArray =
BEGIN
RETURN
dateArray{Fmt.Int(date.year), Fmt.Int(ORD(date.month) + 1), Fmt.Int(date.day),
Fmt.Int(date.hour), Fmt.Int(date.minute), Fmt.Int(date.second)};
END DateArray;
BEGIN
TRY
file := FS.Status("test.txt");
date := Date.FromTime(file.modificationTime);
IO.Put(Fmt.FN("%s-%02s-%02s %02s:%02s:%02s", DateArray(date)));
IO.Put("\n");
EXCEPT
| OSError.E => IO.Put("Error: Failed to get file status.\n");
END;
END ModTime.

View file

@ -0,0 +1,22 @@
MODULE SetModTime EXPORTS Main;
IMPORT Date, FS;
<*FATAL ANY*>
VAR
date: Date.T;
BEGIN
(* Set the modification time to January 1st, 1999 *)
date.year := 1999;
date.month := Date.Month.Jan;
date.day := 1;
date.hour := 0;
date.minute := 0;
date.second := 0;
date.offset := 21601;
date.zone := "CST";
FS.SetModificationTime("test.txt", Date.ToTime(date));
END SetModTime.

View file

@ -0,0 +1,29 @@
/* NetRexx */
options replace format comments java crossref symbols binary
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) public static
parse arg fileName
if fileName = '' then fileName = 'data/tempfile01'
mfile = File(fileName)
mtime = mfile.lastModified()
dtime = Date(mtime).toString()
say 'File' fileName 'last modified at' dtime
say
if mfile.setLastModified(0) then do
dtime = Date(mfile.lastModified()).toString()
say 'File modification time altered...'
say 'File' fileName 'now last modified at' dtime
say
say 'Resetting...'
mfile.setLastModified(mtime)
dtime = Date(mfile.lastModified()).toString()
say 'File' fileName 'reset to last modified at' dtime
end
else do
say 'Unable to modify time for file' fileName
end
return

View file

@ -0,0 +1,5 @@
;; print modification time
(println (date (file-info "input.txt" 6)))
;; set modification time to now (Unix)
(! "touch -m input.txt")

View file

@ -0,0 +1,11 @@
import os, strutils, times
if paramCount() == 0: quit(QuitSuccess)
let fileName = paramStr(1)
# Get and display last modification time.
var mtime = fileName.getLastModificationTime()
echo "File \"$1\" last modification time: $2".format(fileName, mtime.format("YYYY-MM-dd HH:mm:ss"))
# Change last modification time to current time.
fileName.setLastModificationTime(now().toTime())

View file

@ -0,0 +1,7 @@
#load "unix.cma";;
open Unix;;
let mtime = (stat filename).st_mtime;; (* seconds since the epoch *)
utimes filename (stat filename).st_atime (time ());;
(* keep atime unchanged
set mtime to current time *)

View file

@ -0,0 +1,7 @@
use System.IO.File;
class Program {
function : Main(args : String[]) ~ Nil {
File->ModifiedTime("file_mod.obs")->ToString()->PrintLine();
}
}

View file

@ -0,0 +1,11 @@
NSFileManager *fm = [NSFileManager defaultManager];
// Pre-OS X 10.5
NSLog(@"%@", [[fm fileAttributesAtPath:@"input.txt" traverseLink:YES] fileModificationDate]);
[fm changeFileAttributes:[NSDictionary dictionaryWithObject:[NSDate date] forKey:NSFileModificationDate]
atPath:@"input.txt"];
// OS X 10.5+
NSLog(@"%@", [[fm attributesOfItemAtPath:@"input.txt" error:NULL] fileModificationDate]);
[fm setAttributes:[NSDictionary dictionaryWithObject:[NSDate date] forKey:NSFileModificationDate]
ofItemAtPath:@"input.txt" error:NULL];

View file

@ -0,0 +1 @@
File new("myfile.txt") modified

View file

@ -0,0 +1,4 @@
FILE-INFO:FILE-NAME = 'c:/temp'.
MESSAGE
STRING( FILE-INFO:FILE-MOD-TIME, 'HH:MM:SS' )
VIEW-AS ALERT-BOX

View file

@ -0,0 +1,5 @@
declare
[Path] = {Module.link ['x-oz://system/os/Path.ozf']}
Modified = {Path.mtime "input.txt"} %% posix time
in
{Show {OsTime.localtime Modified}} %% human readable record

View file

@ -0,0 +1,9 @@
<?php
$filename = 'input.txt';
$mtime = filemtime($filename); // seconds since the epoch
touch($filename,
time(), // set mtime to current time
fileatime($filename)); // keep atime unchanged
?>

View file

@ -0,0 +1,9 @@
my $mtime = (stat($file))[9]; # seconds since the epoch
# you should use the more legible version below:
use File::stat qw(stat);
my $mtime = stat($file)->mtime; # seconds since the epoch
utime(stat($file)->atime, time, $file);
# keep atime unchanged
# set mtime to current time

View file

@ -0,0 +1,11 @@
(notonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- file i/o
-- (however get as per the JavaScript entry above might be doable if needed)</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">filename</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"test.txt"</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">get_file_date</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_file_date</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">))</span>
<span style="color: #004080;">bool</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">set_file_date</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_file_date</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filename</span><span style="color: #0000FF;">))</span>
<!--

View file

@ -0,0 +1,5 @@
(let File "test.file"
(and
(info File)
(prinl (stamp (cadr @) (cddr @))) ) # Print date and time in UTC
(call 'touch File) ) # Set modification time to "now"

View file

@ -0,0 +1,2 @@
;;; Print modification time (seconds since Epoch)
sysmodtime('file') =>

View file

@ -0,0 +1,8 @@
$modificationTime = (Get-ChildItem file.txt).LastWriteTime
Set-ItemProperty file.txt LastWriteTime (Get-Date)
$LastReadTime = (Get-ChildItem file.txt).LastAccessTime
Set-ItemProperty file.txt LastAccessTime(Get-Date)
$CreationTime = (Get-ChildItem file.txt).CreationTime
Set-ItemProperty file.txt CreationTime(Get-Date)

View file

@ -0,0 +1,3 @@
Debug FormatDate("%yyyy/%mm/%dd", GetFileDate("file.txt",#PB_Date_Modified))
SetFileDate("file.txt",#PB_Date_Modified,Date(1987, 10, 23, 06, 43, 15))
Debug FormatDate("%yyyy/%mm/%dd - %hh:%ii:%ss", GetFileDate("file.txt",#PB_Date_Modified))

View file

@ -0,0 +1,13 @@
import os
#Get modification time:
modtime = os.path.getmtime('filename')
#Set the access and modification times:
os.utime('path', (actime, mtime))
#Set just the modification time:
os.utime('path', (os.path.getatime('path'), mtime))
#Set the access and modification times to the current time:
os.utime('path', None)

View file

@ -0,0 +1,7 @@
# Get the value
file.info(filename)$mtime
#To set the value, we need to rely on shell commands. The following works under windows.
shell("copy /b /v filename +,,>nul")
# and on Unix (untested)
shell("touch -m filename")

View file

@ -0,0 +1,3 @@
Function getModDate(f As FolderItem) As Date
Return f.ModificationDate
End Function

View file

@ -0,0 +1,8 @@
/*REXX program obtains and displays a file's time of modification. */
parse arg $ . /*obtain required argument from the CL.*/
if $=='' then do; say "***error*** no filename was specified."; exit 13; end
q=stream($, 'C', "QUERY TIMESTAMP") /*get file's modification time info. */
if q=='' then q="specified file doesn't exist." /*set an error indication message. */
say 'For file: ' $ /*display the file ID information. */
say 'timestamp of last modification: ' q /*display the modification time info. */
/*stick a fork in it, we're all done. */

View file

@ -0,0 +1,2 @@
#lang racket
(file-or-directory-modify-seconds "foo.rkt")

View file

@ -0,0 +1,21 @@
use NativeCall;
class utimbuf is repr('CStruct') {
has int $.actime;
has int $.modtime;
submethod BUILD(:$atime, :$mtime) {
$!actime = $atime;
$!modtime = $mtime.to-posix[0].round;
}
}
sub sysutime(Str, utimbuf --> int32) is native is symbol('utime') {*}
sub MAIN (Str $file) {
my $mtime = $file.IO.modified orelse .die;
my $ubuff = utimbuf.new(:atime(time),:mtime($mtime));
sysutime($file, $ubuff);
}

View file

@ -0,0 +1,3 @@
name$ = DIR$("input.txt", 0)
PRINT "File date: "; FileRec.Date
PRINT "File time: "; FileRec.Time

View file

@ -0,0 +1,9 @@
load "stdlib.ring"
see GetFileInfo( "test.ring" )
func GetFileInfo cFile
cOutput = systemcmd("dir /T:W " + cFile )
aList = str2list(cOutput)
cLine = aList[6]
aInfo = split(cLine," ")
return aInfo

View file

@ -0,0 +1,11 @@
#Get modification time:
modtime = File.mtime('filename')
#Set the access and modification times:
File.utime(actime, mtime, 'path')
#Set just the modification time:
File.utime(File.atime('path'), mtime, 'path')
#Set the access and modification times to the current time:
File.utime(nil, nil, 'path')

View file

@ -0,0 +1,23 @@
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
print '
#f DATEFORMAT("mm/dd/yy") ' set format of file date to template given
#f TIMEFORMAT("hh:mm:ss") ' set format of file time to template given
for i = 1 to #f rowcount() ' loop through the files
if #f hasanswer() then ' or loop with while #f hasanswer()
print "nextfile info: ";#f nextfile$(" ") ' set the delimiter for nextfile info
print "name: ";name$ ' file name
print "size: ";#f SIZE() ' file size
print "date: ";#f DATE$() ' file date
print "time: ";#f TIME$() ' file time
print "isdir: ";#f ISDIR() ' is it a directory or file
name$ = #f NAME$()
shell$("touch -t 201002032359.59 ";name$;""") ' shell to os to set date
print
end if
next

View file

@ -0,0 +1,12 @@
use std::fs;
fn main() -> std::io::Result<()> {
let metadata = fs::metadata("foo.txt")?;
if let Ok(time) = metadata.accessed() {
println!("{:?}", time);
} else {
println!("Not supported on this platform");
}
Ok(())
}

View file

@ -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)
}

View file

@ -0,0 +1,11 @@
$ include "seed7_05.s7i";
include "osfiles.s7i";
include "time.s7i";
const proc: main is func
local
var time: modificationTime is time.value;
begin
modificationTime := getMTime("data.txt");
setMTime("data.txt", modificationTime);
end func;

View file

@ -0,0 +1,6 @@
var file = File.new(__FILE__);
say file.stat.mtime; # seconds since the epoch
# keep atime unchanged
# set mtime to current time
file.utime(file.stat.atime, Time.now);

View file

@ -0,0 +1,2 @@
slate[1]> (File newNamed: 'LICENSE') fileInfo modificationTimestamp.
1240349799

View file

@ -0,0 +1,3 @@
|a|
a := File name: 'input.txt'.
(a lastModifyTime) printNl.

View file

@ -0,0 +1,6 @@
val mtime = OS.FileSys.modTime filename; (* returns a Time.time data structure *)
(* unfortunately it seems like you have to set modification & access times together *)
OS.FileSys.setTime (filename, NONE); (* sets modification & access time to now *)
(* equivalent to: *)
OS.FileSys.setTime (filename, SOME (Time.now ()))

View file

@ -0,0 +1,5 @@
$$ MODE TUSCRIPT
file="rosetta.txt"
ERROR/STOP OPEN (file,READ,-std-)
modified=MODIFIED (file)
PRINT "file ",file," last modified: ",modified

View file

@ -0,0 +1,5 @@
# Get the modification time:
set timestamp [file mtime $filename]
# Set the modification time to now:
file mtime $filename [clock seconds]

View file

@ -0,0 +1 @@
T=`stat -c %Y $F`

View file

@ -0,0 +1 @@
T=`stat -c %y $F`

View file

@ -0,0 +1,3 @@
# Note the quotation marks -- very important!
T="2000-01-01 01:02:03.040506070 -0800"
touch -c -d "$T" $F

View file

@ -0,0 +1,2 @@
T=200102030405.06
touch -c -t $T $F

View file

@ -0,0 +1,2 @@
T=02030405
touch -c -t $T $F

View file

@ -0,0 +1 @@
touch -c $F

View file

@ -0,0 +1,8 @@
decl java.util.Date d
decl file f
f.open "example.txt"
d.setTime (f.lastmodified)
out d endl console
f.setlastmodified 10

View file

@ -0,0 +1 @@
WScript.Echo CreateObject("Scripting.FileSystemObject").GetFile("input.txt").DateLastModified

View file

@ -0,0 +1 @@
Num_Type(File_Stamp_Time("input.txt"))

View file

@ -0,0 +1,2 @@
File_Stamp_String(10, "input.txt")
Reg_Type(10)

Some files were not shown because too many files have changed in this diff Show more