v / examples
Raw file
		
1#!/usr/local/bin/v
2
3// The shebang above associates the file to V on Unix-like systems,
4// so it can be run just by specifying the path to the file
5// once it's made executable using `chmod +x`.
6
7// Note that you can also use: `#!/usr/bin/env -S v crun`, if your system supports the -S flag to env
8// The benefit is that in this case, v could be anywhere in your path, while /usr/bin/env is guaranteed
9// to be present on most Unix systems in that exact place.
10
11for _ in 0 .. 3 {
12 println('V script')
13}
14
15println('\nMaking dir "v_script_dir".')
16mkdir('v_script_dir')?
17
18println("\nEntering into v_script_dir and listing it's files.")
19chdir('v_script_dir')?
20files := ls('.') or { panic(err) }
21println(files)
22
23println('\nCreating foo.txt')
24create('foo.txt')?
25
26println('\nFiles:')
27again_ls := ls('.') or { panic(err) }
28println(again_ls)
29
30println('\nRemoving foo.txt and v_script_dir')
31rm('foo.txt')?
32chdir('../')?
33rmdir('v_script_dir')?
34
35print('\nDoes v_script_dir still exist? ')
36println(exists('v_script_dir'))