Read, write and edit files

While it works on a task, DataMind Oda reads files to understand them, writes new files and edits the ones you already have on your computer. This page explains what each kind of step accepts, the limits that apply, and the messages you may see.

Reading a file

A read returns the file's text with its line numbers, so a part read from the middle of a file keeps the file's own numbering. Oda reads text files as UTF-8, and each read covers a window of the file:

PDF files are read page by page instead; Reading PDFs covers the page window, scan handling and the footers. To look for files or text rather than read a file, see Finding files and text.

Reading an image

An image read returns the picture itself; what the step shows is covered in Reading files and images. What the read accepts:

Creating and replacing a file

The write step creates a UTF-8 text file, or replaces the whole text of an existing one. Its result ends with one of two lines:

Creating a file does not need an earlier read. Replacing an existing file does; the checks are described below.

Editing a file

An edit replaces literal text in a file and leaves the rest of it as it was. By default the text to replace must appear exactly once, so the change lands where it is meant to. For a change that is meant for every occurrence, Oda uses the replace-all option, Replace all matches. When the text is not found, or it appears more than once while the change is meant for one place, the edit does not run.

Success is reported as The file <displayPath> has been updated successfully., or, for a replace-all edit, The file <displayPath> has been updated. All occurrences were successfully replaced. An edit with nothing to replace is refused with old_string must be a non-empty string or old_string and new_string must differ.

Before Oda changes a file

Overwriting a whole file needs a prior read in the same chat, and that read sets the version Oda expects to find. When something no longer matches, the change is refused instead of guessing:

In practice:

Questions, answered

How much of a file does Oda read at once?

By default, one read covers up to 2,000 lines and up to 51,200 bytes of the result, and a single line is kept to 2,000 characters. A longer file is read in parts, and the note at the end of each part says where to continue.

What does the note (Showing lines 31-60 of 180. Use offset=61 to continue.) mean?

The read covered lines 31 to 60 of the 180-line file. offset=61 is where Oda continues from when it needs the rest; you do not have to do anything about it.

Why is one of my lines cut off with (line truncated to 2000 chars)?

That line is longer than the limit of 2,000 characters, so the read shows it cut and marked. The full text stays in the file. Ask Oda for the part you need, or open the file to read that line in full.

How do I know whether Oda created or changed a file?

The step's result ends with Created file when the file did not exist, and Updated file when an existing file was replaced.

Why does Oda need to read a file before overwriting it?

So that it replaces the file's current content, not an outdated copy. Oda reads the file first and keeps the version it saw, and it replaces the file only while that version still matches. A replacement that arrives without a read is refused with cannot modify "<path>": file has not been read — read the file, then retry, and Oda reads the file and retries.

Oda says the file changed since it was read. What now?

Nothing was changed by the refused step: the file changed outside Oda after it was read. Oda reads the file again (re-read the file, then retry) and then repeats your change against the current text.

Can Oda edit a file it has not read?

For a small edit, yes: the text being replaced must match the file exactly, and that match is its own check. Replacing a whole file is different: Oda reads the file first, then replaces it.

Why can't Oda read my image?

One of four reasons, each with its own message on the step:

Which image formats can Oda read?

PNG, JPEG, WebP and GIF, including files without a file extension: those are identified by their content. Other formats need converting first.

Why was my image scaled down?

It was larger than the limits Oda can take in one result, so a smaller copy was made and shown to you. The note under the picture ends (downscaled from <W>x<H> px; multiply coordinates by <x> to locate features in the original file): multiply a position in the shown copy by that factor to find it in the original file.