logo
VitNX3 Documentation

# File.Split Method

Namespace: VitNX3.Functions.FileSystem
Assembly: VitNX3 (in VitNX3.dll)
Splits the file as many.
VB
C#
F#
C++
JScript
Copy

    public static void Split(
       string fileInputPath,
       string folderOutputPath,
       int countOfOutputFiles
    )

    This language is not supported or no code example is available.

#### Parameters

fileInputPath
  string

The file input path.

folderOutputPath
  string

The folder output path.

countOfOutputFiles
  int

The count of output files.

Source code
VB
C#
F#
C++
JScript
Copy

    public static void Split(string fileInputPath,
         string folderOutputPath,
         int countOfOutputFiles)
     {
         byte[] byteSource = System.IO.File.ReadAllBytes(fileInputPath);
         FileInfo fiSource = new FileInfo(fileInputPath);
         int partSize = (int)Math.Ceiling((double)(fiSource.Length / countOfOutputFiles));
         int fileOffset = 0;
         string currPartPath;
         FileStream fsPart;
         int sizeRemaining = (int)fiSource.Length;
         for (int i = 0; i < countOfOutputFiles; i++)
         {
             currPartPath = folderOutputPath + "\\" + fiSource.Name + "." + string.Format(@"{0:D4}", i) + ".part";
             if (!System.IO.File.Exists(currPartPath))
             {
                 fsPart = new FileStream(currPartPath, FileMode.CreateNew);
                 sizeRemaining = (int)fiSource.Length - (i * partSize);
                 if (sizeRemaining < partSize)
                     partSize = sizeRemaining;
                 fsPart.Write(byteSource,
                     fileOffset,
                     partSize);
                 fsPart.Close();
                 fileOffset += partSize;
             }
         }
     }

    This language is not supported or no code example is available.

Applies to

#### .NET Framework

Supported in: 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8

#### .NET Core

Supported in: 5.0+, 6.0+
See Also
File Class
VitNX3.Functions.FileSystem Namespace