Jump to content
Tuts 4 You

Need some C++ APIs


LCF-AT

Recommended Posts

Posted

Hi again,

short question.Just need to know which APIs I have to use to get the filesize by handle and a C++ API to delete the file if the filesize was 0 etc you know.So I use fopen to create a file then fwrite to write bytes into file (if so) and now I need a C++ API for GetFileSize API & DeleteFile API.So I can't use the same handle from fopen API with GetFileSize API you know.DeleteFile API is ok so far so this only need a path to file.

Thanks

  • Like 1
Posted
#include <cstdio>
int main() {
 
    const int result = remove("C:\\Temp\\somefile.txt");
    return 0;
}
Posted
Quote

I use fopen to create a file then fwrite to write bytes into file

Here, you work by pointer... and you can get file size like this:

#include <stdio.h>
int main() {
    FILE* lpFile;
    lpFile = fopen("empty.txt","r");
    if (lpFile != NULL)  {
        fseek(lpFile, 0, SEEK_END);
        int fileSize = ftell(lpFile);
        printf("FileSize is: %u\n", fileSize);
        fseek(lpFile, 0, SEEK_SET);
        fclose (lpFile);
    }
    getchar();
    return 0;
}

if you need to work by handle (GetFileSize), it's better to use CreateFile and WriteFile instead of fopen and fwrite...

  • Like 2
Posted

Hi guys,

thanks for your answers about it. :) As I said I just needed to know some C++ APIs about it I can use directly.Now it works so far on a first test.Thanks again.

PS: I am also no C++ coder and just use rarly such APIs etc.

greetz

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...