SplitFileByLines (split a text file into chunks)
ts
function SplitFileByLines(
path: string, // required
linesPerChunk: number, // required
outputDir: string // required
): number;NOTE
This function is available as of Syncplify Server! v7.1.1. If you are running an older version, upgrade to v7.1.1 or later to use it.
Splits a text file into multiple smaller files, each containing at most linesPerChunk lines. The output files are written to outputDir and are named after the source file with a zero-padded numeric suffix inserted before the extension — for example, report_0001.csv, report_0002.csv, and so on.
This is useful for breaking up large files before transferring them or feeding them to systems that have row-count limits.
| Parameter | Type | Requirement | Explanation |
|---|---|---|---|
path | string | required | Fully qualified path to the source file to split |
linesPerChunk | number | required | Maximum number of lines per output file |
outputDir | string | required | Directory where the chunk files will be written |
| Return value | Explanation |
|---|---|
| number (≥ 1) | Number of chunk files created |
-1 | The operation failed (file not found, directory not writable, etc.) |
Example
ts
var chunks = SplitFileByLines('/var/data/big_report.csv', 1000, '/var/split/');
if (chunks < 0) {
Log('Split failed.');
} else {
Log('Created ' + chunks + ' chunk files.');
}Given a source file /var/data/big_report.csv with 2500 lines and linesPerChunk = 1000, the output would be:
| Output file | Lines |
|---|---|
big_report_0001.csv | 1000 |
big_report_0002.csv | 1000 |
big_report_0003.csv | 500 |
NOTE
For binary or non-line-oriented files, use SplitFileBySize instead.
