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

    subashree

    Member

    Updated: Oct 14, 2024
    Views: 1.0K
    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;
    }
    }
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • PraveenKumar Purushothaman

    MemberFeb 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... 😀
    Are you sure? This action cannot be undone.
    Cancel
  • subashree

    MemberFeb 4, 2012

    Praveen-Kumar
    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... 😀
    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
    Are you sure? This action cannot be undone.
    Cancel
  • PraveenKumar Purushothaman

    MemberFeb 4, 2012

    [​IMG]
    This was the frames I was talking about... Did you miss the PNG Signature in the rest of the frames???
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register