LCF-AT Posted March 22, 2016 Posted March 22, 2016 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 1
HAMID Posted March 22, 2016 Posted March 22, 2016 http://stackoverflow.com/questions/14628141/faster-way-to-get-file-size-information-c 1
HAMID Posted March 22, 2016 Posted March 22, 2016 #include <cstdio> int main() { const int result = remove("C:\\Temp\\somefile.txt"); return 0; }
Insid3Code Posted March 22, 2016 Posted March 22, 2016 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... 2
Alzri2 Posted March 22, 2016 Posted March 22, 2016 I made it in my library (more incoming functions soon): https://github.com/Z-Rantom/AU4-Library/blob/master/AU4Lib/files.cpp "au_FileGetSize" is the name of the function.
LCF-AT Posted March 22, 2016 Author Posted March 22, 2016 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 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now