Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
9
Task/File-size/AWK/file-size-1.awk
Normal file
9
Task/File-size/AWK/file-size-1.awk
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
@load "filefuncs"
|
||||
BEGIN {
|
||||
printsize("input.txt")
|
||||
printsize("/input.txt")
|
||||
}
|
||||
function printsize(name ,fd) {
|
||||
stat(name, fd)
|
||||
printf("%s\t%s\n", name, fd["size"])
|
||||
}
|
||||
44
Task/File-size/AWK/file-size-2.awk
Normal file
44
Task/File-size/AWK/file-size-2.awk
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
BEGIN {
|
||||
|
||||
# Windows
|
||||
out = system2var("for %I in (input.txt) do @echo %~zI")
|
||||
printf("input.txt\t%s\n", out)
|
||||
out = system2var("for %I in (\input.txt) do @echo %~zI")
|
||||
printf("\input.txt\t%s\n", out)
|
||||
|
||||
# Non-Windows
|
||||
out = getline2var("ls -l input.txt")
|
||||
split(out, size, " ")
|
||||
printf("input.txt\t%s\n", size[5])
|
||||
out = getline2var("ls -l /input.txt")
|
||||
split(out, size, " ")
|
||||
printf("/input.txt\t%s\n", size[5])
|
||||
}
|
||||
|
||||
# Windows system() method
|
||||
function system2var(command ,tempfile, cmd, out, rec, data, i) {
|
||||
tempfile = "C:\\TEMP\\TMP.TMP"
|
||||
cmd = command " > " tempfile
|
||||
system(cmd)
|
||||
close(cmd)
|
||||
while (getline rec < tempfile > 0) {
|
||||
if ( ++i == 1 )
|
||||
data = rec
|
||||
else
|
||||
data = data "\n" rec
|
||||
}
|
||||
return(data)
|
||||
}
|
||||
|
||||
# Non-windows getline method
|
||||
function getline2var(command ,fish, scale, ship) {
|
||||
command = command " 2>/dev/null"
|
||||
while ( (command | getline fish) > 0 ) {
|
||||
if ( ++scale == 1 )
|
||||
ship = fish
|
||||
else
|
||||
ship = ship "\n" fish
|
||||
}
|
||||
close(command)
|
||||
return ship
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
# usage: awk -f filesize.awk -v fn=input.txt
|
||||
|
||||
BEGIN { # Filesize on Unix, using ls
|
||||
#system("ls -l")
|
||||
|
||||
if(!fn) fn ="input.txt"
|
||||
cmd="ls -l " fn
|
||||
print "#", cmd
|
||||
system(cmd)
|
||||
|
||||
cmd | getline x
|
||||
close(cmd)
|
||||
#print x
|
||||
n=split(x,stat," ")
|
||||
#for (i in stat) {print i, stat[i] }
|
||||
print "file:", stat[9], "size:", stat[5]
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
(import '[java.io File])
|
||||
(require '[clojure.java.io :as io])
|
||||
(defn show-size [filename]
|
||||
(println filename "size:" (.length (File. filename))))
|
||||
(println filename "size:" (.length (io/file filename))))
|
||||
|
||||
(show-size "input.txt")
|
||||
(show-size "/input.txt")
|
||||
|
|
|
|||
2
Task/File-size/Elixir/file-size.elixir
Normal file
2
Task/File-size/Elixir/file-size.elixir
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
IO.puts File.stat!("input.txt").size
|
||||
IO.puts File.stat!("/input.txt").size
|
||||
|
|
@ -1,11 +1,16 @@
|
|||
/*REXX pgm to verify a file's size (by reading the lines) on default MD.*/
|
||||
parse arg iFID /*let user specify the file ID. */
|
||||
if iFID='' then iFID="FILESIZ DAT A" /*Not specified? Then use default*/
|
||||
say 'size of' iFID "=" filesize(iFID) 'bytes' /*on the default MD.*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*REXX pgm to verify a file's size */
|
||||
parse arg iFID . /*let user specify the file ID. */
|
||||
if iFID=='' then iFID="FILESIZ.DAT" /*Not specified? Then use default*/
|
||||
say 'size of' iFID':'
|
||||
Say chars(ifid) '(CR LF included)'
|
||||
Call lineout ifid /* close the file */
|
||||
say filesize(ifid) '(net data)'
|
||||
Call lineout ifid
|
||||
exit
|
||||
|
||||
/*──────────────────────────────────FILESIZE subroutine─────────────────*/
|
||||
filesize: parse arg f; $=0; do while lines(f)\==0
|
||||
$=$+length(linein(f))
|
||||
end /*while*/
|
||||
return $
|
||||
filesize: parse arg f;
|
||||
sz=0;
|
||||
Do while lines(f)\==0
|
||||
sz=sz+length(linein(f))
|
||||
End
|
||||
return sz
|
||||
|
|
|
|||
11
Task/File-size/REXX/file-size-3.rexx
Normal file
11
Task/File-size/REXX/file-size-3.rexx
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/*REXX pgm to verify a file's size (by reading the lines) on default MD.*/
|
||||
parse arg iFID /*let user specify the file ID. */
|
||||
if iFID='' then iFID="FILESIZ DAT A" /*Not specified? Then use default*/
|
||||
say 'size of' iFID "=" filesize(iFID) 'bytes' /*on the default MD.*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
|
||||
/*──────────────────────────────────FILESIZE subroutine─────────────────*/
|
||||
filesize: parse arg f; $=0; do while lines(f)\==0
|
||||
$=$+length(linein(f))
|
||||
end /*while*/
|
||||
return $
|
||||
|
|
@ -1,7 +1,18 @@
|
|||
fn main() {
|
||||
let path_wd = Path::new("input.txt");
|
||||
println!("{}", path_wd.stat().size);
|
||||
use std::{env, fs, process};
|
||||
use std::io::{self, Write};
|
||||
use std::fmt::Display;
|
||||
|
||||
fn main() {
|
||||
let file_name = env::args().nth(1).unwrap_or_else(|| exit_err("No file name supplied", 1));
|
||||
let metadata = fs::metadata(file_name).unwrap_or_else(|e| exit_err(e, 2));
|
||||
|
||||
println!("Size of file.txt is {} bytes", metadata.len());
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn exit_err<T: Display>(msg: T, code: i32) -> ! {
|
||||
writeln!(&mut io::stderr(), "Error: {}", msg).expect("Could not write to stdout");
|
||||
process::exit(code)
|
||||
}
|
||||
|
||||
let path_root = Path::new("/input.txt");
|
||||
println!("{}", path_root.stat().size);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue