c# -help in finding logical error in file stripping.

subashree
@subashree-Xch6Ab โ€ข Oct 14, 2024

the following is a snippet for splitting the file(from parameter FileInputPath) into the number of splits(given as outputfiles) to the specified folder (FolderOUtputPath).
the files are split.(my file s an image here). wen the image s split ..oli the first split has the stripped image...the other files r invalid. pls help me ...


privatevoid SplitFile(string FileInputPath, string FolderOutputPath, intOutputFiles)
{

Byte[] byteSource = System.IO.File.ReadAllBytes(FileInputPath);

FileInfo fiSource = newFileInfo(textBox1.Text);

int partSize = (int)Math.Ceiling((double)(fiSource.Length / OutputFiles));

int fileOffset = 0;

string currPartPath;

FileStream fsPart;

int sizeRemaining = (int)fiSource.Length;

for (inti = 0; i < OutputFiles; i++)
{


currPartPath = FolderOutputPath +

"\\" + String.Format(@"{0: D4}", i) + fiSource.Name;



if (!File
.Exists(currPartPath))
{
fsPart =

newFileStream(currPartPath, FileMode
.CreateNew);
sizeRemaining = (

int
)fiSource.Length - (i * partSize);

if
(sizeRemaining < partSize)
{
partSize = sizeRemaining;
}
fsPart.Write(byteSource, fileOffset, partSize);
fsPart.Close();
fileOffset += partSize;
}
}

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • PraveenKumar Purushothaman

    @praveenkumar-66Ze92 • Feb 2, 2012

    Is the first image a full one? I don't think so... If that shouldn't be a full one, then the rest are missing their headers. So, just prepend the headers to the rest of the files and check it out... ๐Ÿ˜€

  • subashree

    @subashree-Xch6Ab • Feb 4, 2012

    Praveen-KumarIs the first image a full one? I don't think so... If that shouldn't be a full one, then the rest are missing their headers. So, just prepend the headers to the rest of the files and check it out... ๐Ÿ˜€

    no...i dont get wat u r trying to say...wen i run this code the input image file s supposed to b stripped...wen i give the number of splits as 3(say) then the first splitted image has the stripped image(1/3rd of the image..remaining ll be blank) but the other files should hav the remaining part of the image..but it s an invalid...my doubt is if the snippet works for first iteration it should do for the rest too...

    and wad did u mean by sayib add headers

  • PraveenKumar Purushothaman

    @praveenkumar-66Ze92 • Feb 4, 2012

    [โ€‹IMG]
    This was the frames I was talking about... Did you miss the PNG Signature in the rest of the frames???