How to delete a file using GitHub - avitalique/xk6-file: k6 extension for writing files?
Hi @shine1691
This is a community extension, if the maintainer does not respond here, I would suggest you open the question in the. I can see someone already asked how to delete a row, which seems is not supported. So maybe deleting a file isn’t either. At least based on the example provided it seems like you can only write and append.
import file from 'k6/x/file';
const filepath = 'sample-output.txt';
export default function () {
file.writeString(filepath, 'New file. First line.\n');
file.appendString(filepath, `Second line. VU: ${__VU} - ITER: ${__ITER}`);
}
Cheers!
An option would be to include the xk6-exec extension as well. With that, you could delete your file.
import file from 'k6/x/file';
import exec from 'k6/x/exec';
const filepath = 'sample-output.txt';
export default function () {
file.writeString(filepath, 'New file. First line.\n');
file.appendString(filepath, `Second line. VU: ${__VU} - ITER: ${__ITER}`);
exec.command("rm", [filepath])
}
1 Like