Add usage examples to README.md

This commit is contained in:
The Magician 2023-12-12 16:45:17 +00:00
parent 3f173d2335
commit 1500d7416e
1 changed files with 37 additions and 0 deletions

View File

@ -13,3 +13,40 @@ The `nextfile` library actually contains two exported modules, `nextfile` and `p
- If the previous filename ends in a letter, then the next file will bump it to the next letter. For example, if the previous file were "200a.png", the next file would be "200b.png". - If the previous filename ends in a letter, then the next file will bump it to the next letter. For example, if the previous file were "200a.png", the next file would be "200b.png".
By default, `nextfile` will give the next file the same file extension as the previous file; there is a second optional parameter for specifying the file extension. By default, `nextfile` will give the next file the same file extension as the previous file; there is a second optional parameter for specifying the file extension.
## Examples
### Create Test Files
```sh
user@box:~$ cd $(mktemp -d)
user@box:/tmp/tmp.g9nf7G4U1C $ touch {1,2,3}.txt
```
### Use prevfile
```lua
local prevfile = require("prevfile")
local pfile = prevfile.prevfile("/tmp/tmp.g9nf7G4U1C")
print(pfile) -- 3.txt
```
### Use nextfile
```lua
local nextfile = require("nextfile")
local nfile = nextfile.nextfile("/tmp/tmp.g9nf7G4U1C")
print(nfile) -- 4.txt
-- Specify an alternate file extension
nfile = nextfile.nextfile("/tmp/tmp.g9nf7G4U1C", "png")
print(nfile) -- 4.png
```
### Create Alphabetical Test File
```sh
user@box:/tmp/tmp.g9nf7G4U1C $ touch 4a.txt
```
```lua
local nextfile = require("nextfile")
local nfile = nextfile.nextfile("/tmp/tmp.g9nf7G4U1C")
print(nfile) -- 4b.txt
```