https://github.com/objectionary/eo-files
Input/Output and File System Objects for EO Programming Laguage
https://github.com/objectionary/eo-files
eolang java
Last synced: 6 months ago
JSON representation
Input/Output and File System Objects for EO Programming Laguage
- Host: GitHub
- URL: https://github.com/objectionary/eo-files
- Owner: objectionary
- License: mit
- Archived: true
- Created: 2021-10-04T14:08:57.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-08-07T03:43:11.000Z (almost 2 years ago)
- Last Synced: 2025-07-19T17:28:52.061Z (12 months ago)
- Topics: eolang, java
- Language: Java
- Homepage: https://www.eolang.org
- Size: 277 KB
- Stars: 13
- Watchers: 4
- Forks: 5
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README

[](https://www.elegantobjects.org)
[](http://www.rultor.com/p/objectionary/eo-files)
[](https://www.jetbrains.com/idea/)
[](https://github.com/objectionary/eo-files/actions/workflows/mvn.yml)
[](http://www.0pdd.com/p?name=objectionary/eo-files)
[](https://codecov.io/gh/objectionary/eo-files)
[](https://maven-badges.herokuapp.com/maven-central/org.eolang/eo-files)
[](https://hitsofcode.com/view/github/objectionary/eo-files)

[](https://github.com/objectionary/eo-files/blob/master/LICENSE.txt)
**This repository is deprecated! We've moved all EO objects from this repository
to [objectionary/eo](https://github.com/objectionary/eo).**
[EO](https://www.eolang.org) objects for file system.
This is how you list all text files in a directory recursively:
```
each. > @
filteredi.
QQ.collections.list
walk.
QQ.fs.dir "/tmp"
"**/*"
[f i]
and. > @
f.is-dir.not
matches.
compile.
QQ.txt.regex
"/.*\\.txt$/"
f
[f]
QQ.io.stdout > @
QQ.txt.sprintf "file: %s\n" f
```
You are welcome to add more primitives to this lib.
Simple manipulations:
```
# Make a new object representing a file on disc
QQ.fs.file > f
"/tmp/foo.txt"
# Get its name:
QQ.io.stdout
QQ.txt.sprintf
"File name is: %s"
f
# Does it exist?
f.exists
# Is it a directory?
f.is-dir
# Touch it, to make sure it exists
f.touch
# Delete the file:
f.rm
# Rename/move it:
f.mv "/tmp/bar.txt"
# Get the size of it in bytes:
f.size > s
```
Reading:
```
# Read binary content into the "output," in 1024-bytes chunks;
# the "memory-as-output" is an abstract object with one free attribute,
# which is the memory where the bytes will be stored:
QQ.fs.file "/tmp/foo.txt" > f
memory > m
QQ.io.copied
f.as-input
QQ.io.memory-as-output m
1024
```
Writing:
```
# Write binary content, taking it from the "input",
# until input turns into a non-empty "bytes"; here the
# "mode" is the same as the mode in POSIX fopen();
# if the file is absent, it will be created:
QQ.fs.file "/tmp/foo.txt" > f
QQ.io.copied
QQ.io.bytes-as-input
"你好, world!".as-bytes
f.as-output "w+"
```
Smart object to help read content fast:
```
# This is the entire binary content of the file:
QQ.fs.content f
```
Directories:
```
# Make an object representing a directory on disc:
QQ.fs.directory > d
"/tmp"
# Make it if doesn't exist:
d.mkdir
# Delete it recursively:
d.rm-rf
# List all files recursively:
d.walk "**/*.txt"
```
Temporary files:
```
# This is a system directory for temporary files:
QQ.fs.tmpdir > d
# Create an empty temporary file in a directory
d.tmpfile.@ > f
```
Name manipulations:
```
# Add path segment to existing file:
QQ.fs.file "/tmp" > f
f.resolve "foo.txt"
# Get directory name:
QQ.fs.dir-name f
# Get base name (no directory, not extension):
QQ.fs.base-name f
# Get extension:
QQ.fs.ext-name f
```
## How to Contribute
Fork repository, make changes, send us a pull request.
We will review your changes and apply them to the `master` branch shortly,
provided they don't violate our quality standards. To avoid frustration,
before sending us your pull request please run full Maven build:
```bash
$ mvn clean install -Pqulice
```
You will need Maven 3.3+ and Java 8+.