Thread: Regarding file size

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    8

    Regarding file size

    Hi,

    A process is writing data continuously to a file . I need to stop the write operation if the file size has reached 1GB. Is there any way to check file size when it is opened for the write operation.

    I could do the same using scripts. Can this be done using C Programming ?

    Regards,
    Shilpa
    Last edited by shilpac; 12-23-2013 at 10:21 PM.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Yes. Just keep a counter of how many bytes you have written. There are file operations that can check a file size, but since you're doing all the writing, it's easiest if you just keep count and stop after 1GB.

  3. #3
    Rat with a C++ compiler Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    203
    He didn't say whether he was creating all those files anew. He could be appending as well, which would mean he'd need to read the file and seek to the end to find the current file size, THEN keep track of how many bytes he's appending relative to the bytes that were already there.
    How to ask smart questions
    Code:
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};
    WriteProcessMemory(hTaskManager,(LPVOID)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation"),rgucOverWrite,5,&dwBytesOverwritten);

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    8
    anduril462 and Rodaxoleaux,

    In my program, process 'X' writes data to the fifo and another process 'Y' reads data from fifo and write it to a file. I don't have access to code of process 'X', I don't know how many bytes are written each time.

    Thanks,
    Shilpa

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Do you have access to the code for process 'Y'? Since this is the process that writes to the file, this is where you should be implementing the suggestions above.

  6. #6
    Registered User
    Join Date
    Oct 2012
    Posts
    8
    Matticus,

    I don't have access.

    Thanks,
    Shilpa
    Last edited by shilpac; 12-25-2013 at 07:55 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2012, 10:35 AM
  2. Replies: 16
    Last Post: 04-20-2009, 04:33 PM
  3. Replies: 3
    Last Post: 08-13-2006, 05:58 AM
  4. getting file size from FILE* struct
    By duck-billed platypus in forum C++ Programming
    Replies: 3
    Last Post: 01-03-2002, 02:03 AM
  5. File Size and File Size on Disk
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-15-2001, 08:03 PM

Tags for this Thread