os

lhj
summon os

File system

lhj
os.getcwd()                         ## current working directory
os.listdir(".")                     ## list directory contents
os.listdir("/home/user/projects")   ## absolute path
os.path_exists("./data.txt")        ## yep or nope
os.mkdir("./output")                ## create directory
os.remove("./old.txt")              ## delete file

Reading and writing files

lhj
## Write a file
os.write_file("hello.txt", "Hello, world!\n")

## Read it back
forge content = os.read_file("hello.txt")
echo content    ## Hello, world!

Environment variables

lhj
forge home = os.getenv("HOME")
echo home       ## /home/user

os.setenv("MY_APP_ENV", "production")
forge env = os.getenv("MY_APP_ENV")
echo env        ## production

Process

lhj
os.exit(0)       ## exit with code 0
os.exit(1)       ## exit with error code 1

Time

lhj
forge now = os.time()   ## Unix timestamp as float
echo now                ## 1717363200.342

With sleep:

lhj
echo "starting..."
os.sleep(1)             ## pause for 1 second
echo "done"

Path manipulation

lhj
os.path_join("home", "user", "file.txt")   ## home/user/file.txt
os.path_basename("home/user/file.txt")    ## file.txt
os.path_dirname("home/user/file.txt")     ## home/user
os.path_ext("script.lhj")                ## .lhj

Example

lhj
summon os

## Find all .lhj files in the current directory
forge files = os.listdir(".")
forge lhj_files = filter(lam f: strings.ends_with(f, ".lhj"), files)

march f in lhj_files:
    echo f