hi guys, so iam writing a program which creates a .bat file in a directory and copies it to another directory through copyfile...the problem is that while the .bat file is created properly but when it's copied to the other directory an error occurs saying its not a win32 appropriate program and when i open it there is a blanc file...same thing happens when i try it with .txt files..so i wonder if copyfile is used only for .exe files...and if so how can i accomplish it with .bat

win32 api function CopyFile() can be used with any file type. Post your code so that we can see what you did wrong. When CopyFile() returns zero value, get the error number from GetLastError(). Then call FormatMessage() to get the error message text.

Edited 6 Years Ago by Ancient Dragon: n/a

here it is..
#include <stdlib.h>
#include<stdio.h>
#include <windows.h>
#include<string.h>
#include<ctype.h>
int main()
{

FILE* p;


p=fopen("res.bat","w");
fputs("dir",p);


CopyFile("C:\\doc\\res.bat","C:\\new.bat",true);


fclose(p);

}

You opened the file for writing. I'm guessing it should be closed before you call CopyFile.

Adding code tags (click on the [code] icon at the top of your editing window), improves your code's readability, greatly.

Edited 6 Years Ago by Adak: n/a

This question has already been answered. Start a new discussion instead.