0

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

3
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by libathos
0

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 by Ancient Dragon: n/a

0

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);

}

0

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 by Adak: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.