For raw byte chunks, powershell can split files:
set size=<split size>
set file=<file.in>
for %j in (%file%) do (
set /a chunks=%~zj/%size% >nul
for /l %i in (0,1,!chunks!) do (
set /a tail=%~zj-%i*%size% >nul
powershell gc %file% -Encoding byte -Tail !tail! ^| sc %file%_%i -Encoding byte
if %i lss !chunks! FSUTIL file seteof %file%_%i %size% >nul
)
)
These can then be joined by copy
Some systems might need to be prepared to run FSUTIL & enable delayed expansion.
There's another method which extracts smaller parts of a file but the makecab utility encodes the chunks in it's own format so they can't be treated as just raw bytes, similar to a flat binary file eg. via copy.
Unlike what some have stated in some answers, the size of the split files need NOT be a multiple of 512. The chunks, however can then be joined by extrac32.
First make a ddf (text) file or just provide options via /d on command line:
.Set CabinetNameTemplate=test_*.cab; <-- Enter chunk name format
.Set MaxDiskSize=900000; <-- Enter file split/chunk size (doesn't have to be multiple of 512)
.Set ClusterSize=1000
.Set Cabinet=on;
.Set Compress=off; <-- Optional: set compression on to save disk space
.set CompressionType=LZX;
.set CompressionMemory=21
.Set DiskDirectoryTemplate=;
file.in <-- Enter the file name to be split
Then:
makecab /f ddf.txt
To get the original file back, ensure all chunks are in the same directory, then call 1st file in sequence:
extrac32 test_1.cab file.out
MakeCAB introduces the concept of a folder to refer to a contiguous set of compressed bytes.
"MakeCAB takes all of the files in the product or application being compressed, lays the bytes down as one continuous byte stream, compresses the entire stream, chopping it up into folders as appropriate, and then fills up one or more cabinets with the folders."
A third method to split files via CMD & certutil:
set file="x.7z" &REM compressed to generate CRLF pairs
set max=70000000 &REM certutil has max file limit around 74MB
REM Findstr line limit 8k
REM Workaround: wrap in 7z archive to generate CRLF pairs
for %i in (%file%) do (
set /a num=%~zi/%max% >nul &REM No. of chunks
set /a last=%~zi%%max% >nul &REM size of last chunk
if %last%==0 set /a num=num-1 &REM ove zero byte chunk
set size=%~zi
)
ren %file% %file%.0
for /l %i in (1 1 %num%) do (
set /a s1=%i*%max% >nul
set /a s2="(%i+1)*%max%" >nul
set /a prev=%i-1 >nul
echo Writing %file%.%i
type %file%.!prev! | (
(for /l %j in (1 1 %max%) do pause)>nul& findstr "^"> %file%.%i)
FSUTIL file seteof %file%.!prev! %max% >nul
)
if not %last%==0 FSUTIL file seteof %file%.%num% %last% >nul
echo Done.
Notes
- Chunks can be joined by
copy /b
- Filename extensions can be made neater by padding chunk numbers
- Can be looped to split entire directories
See example output below:
29/04/2022 22:14 71,000,000 ATOMIC Blonde.mp4.014
29/04/2022 23:33 71,000,000 ATOMIC Blonde.mp4.015
30/04/2022 00:56 71,000,000 ATOMIC Blonde.mp4.016
30/04/2022 02:16 71,000,000 ATOMIC Blonde.mp4.017
30/04/2022 02:16 71,000,000 ATOMIC Blonde.mp4.018
30/04/2022 03:05 37,601,635 The Young Messiah.mp4.000
30/04/2022 04:25 71,000,000 The Young Messiah.mp4.001
30/04/2022 05:45 71,000,000 The Young Messiah.mp4.002
30/04/2022 07:05 71,000,000 The Young Messiah.mp4.003
30/04/2022 08:25 71,000,000 The Young Messiah.mp4.004
30/04/2022 09:59 71,000,000 The Young Messiah.mp4.005
30/04/2022 11:23 71,000,000 The Young Messiah.mp4.006
30/04/2022 12:47 71,000,000 The Young Messiah.mp4.007
Tested on Win 10.
.bat, it seems like it would be the same difficulty to deploy a.exe.exes do not require installation, and if you can copy text, you can copyexes by base64 encoding them. You're already running code, why not run the code you want instead of trying to build up a rube goldberg style batch file.