1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/examples/v_script.vsh

37 lines
1008 B
V
Raw Normal View History

#!/usr/local/bin/v
2020-10-02 06:18:08 +03:00
// The shebang above associates the file to V on Unix-like systems,
// so it can be run just by specifying the path to the file
// once it's made executable using `chmod +x`.
// Note that you can also use: `#!/usr/bin/env -S v crun`, if your system supports the -S flag to env
// The benefit is that in this case, v could be anywhere in your path, while /usr/bin/env is guaranteed
// to be present on most Unix systems in that exact place.
for _ in 0 .. 3 {
2020-10-02 06:18:08 +03:00
println('V script')
}
2020-10-02 06:18:08 +03:00
println('\nMaking dir "v_script_dir".')
2022-10-16 22:48:40 +03:00
mkdir('v_script_dir')!
2020-10-02 06:18:08 +03:00
println("\nEntering into v_script_dir and listing it's files.")
2022-10-16 22:48:40 +03:00
chdir('v_script_dir')!
files := ls('.') or { panic(err) }
2020-10-02 06:18:08 +03:00
println(files)
2020-10-02 06:18:08 +03:00
println('\nCreating foo.txt')
2022-10-16 22:48:40 +03:00
create('foo.txt')!
2020-10-02 06:18:08 +03:00
println('\nFiles:')
again_ls := ls('.') or { panic(err) }
2020-10-02 06:18:08 +03:00
println(again_ls)
2020-10-02 06:18:08 +03:00
println('\nRemoving foo.txt and v_script_dir')
2022-10-16 22:48:40 +03:00
rm('foo.txt')!
chdir('../')!
rmdir('v_script_dir')!
2020-10-02 06:18:08 +03:00
print('\nDoes v_script_dir still exist? ')
println(exists('v_script_dir'))