I’ve written the following function to resize a given binary file to a given size.
The function works when the file is located at C:\ , but it does not when the file is inside a folder.
Any idea why this is happening?
#include <windows.h>
void truncate_file (long int new_size , char* file_name)
{
char szFileName[MAX_PATH]; //full path
GetCurrentDirectory(MAX_PATH,szFileName);
strcat(szFileName,"\\");
strcat(szFileName,file_name);
HANDLE hFile = CreateFile(szFileName,GENERIC_WRITE,
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
SetFilePointer(hFile,new_size,NULL,FILE_BEGIN);
SetEndOfFile(hFile);
}
Thanks.