File modification time: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(3 intermediate revisions by 3 users not shown)
Line 612:
AD 2022-01-01 AM 05:00:00.000 (Sat) Mountain Standard Time
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
CFURLRef desktopURL = fn FileManagerURLForDirectory( NSDesktopDirectory, NSUserDomainMask )
CFURLRef url = fn URLByAppendingPathComponent( desktopURL, @"file.txt" )
CFDictionaryRef dict = fn FileManagerAttributesOfItemAtURL( url )
 
print dict[@NSFileModificationDate] // Read file's current date
 
// Reset file date to current
fn FileManagerSetAttributesOfItemAtURL( CFURLRef url, @{NSFileModificationDate:fn DateNow )
</syntaxhighlight>
 
 
=={{header|Gambas}}==
Line 719 ⟶ 732:
 
=={{header|Java}}==
<syntaxhighlight lang="java">
</syntaxhighlight>
<syntaxhighlight lang="java">
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());
}
</syntaxhighlight>
<pre>
05/11/23 11:56:58
</pre>
<br />
An alternate demonstration
<syntaxhighlight lang="java">import java.io.File;
import java.util.Date;
Line 800 ⟶ 830:
<syntaxhighlight lang="lang">
# Load the IO module
# Replace "<pathToIO.lm>" with the location where the io.lm langLang module was installed to without "<" and ">"
ln.loadModule(<pathToIO.lm>)
 
Line 1,488 ⟶ 1,518:
{{libheader|Wren-date}}
As there is currently no way for Wren-cli to get or set file modification times, we instead use an embedded script so the C host can do this for us.
<syntaxhighlight lang="ecmascriptwren">/* file_mod_time_wrenFile_modification_time_wren */
 
import "./date" for Date
Line 1,523 ⟶ 1,553:
<br>
We now embed this in the following C program, build and run it:
<syntaxhighlight lang="c">/* gcc file_mod_timeFile_modification_time.c -o file_mod_timeFile_modification_time -lwren -lm */
 
#include <sys/stat.h>
Line 1,661 ⟶ 1,691:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "file_mod_timeFile_modification_time.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
9,476

edits