#include <windows.h>
#include <wincon.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main(void)
{
const numb=50;
BYTE buffer[100]; //buffer for string
LPSTR dir = new CHAR[50],
//dir_info = "Input the current directory:\n",
dir_home = "Current directory is - C:\\Program Files\\Microsoft Visual C++ 6.0\\MSDev98\\MyProjects\\anya",
dir_searching = "\nDirectory for serching is - C:\\temp",
dir_temp = "C:\\Temp",
dir_current = "C:\\Program Files\\Microsoft Visual C++ 6.0\\MSDev98\\MyProjects\\anya",
file_new = "\nEnter please the name of the new File:\n",
file_found = "\nFile: ",
file_not_found = "\nError!File not found!\n",
file_copy = "\nFile copied ...\n",
file_copy_error = "\nFile cannot be copied...\n",
file_info = "\n Information written to the file",
file_write_error = "\nIn file writting was unsuccessful! ";
char divider[2]= "\\";
LPSTR path=new CHAR[50];
char* pattern = new CHAR[50];
DWORD num;
LPTSTR nume;
LPCSTR lpSearchFile = "*.txt";
HANDLE file_txt;
WIN32_FIND_DATA FindFileData;
HANDLE hStdOut = GetStdHandle (STD_OUTPUT_HANDLE);
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
WriteConsole(hStdOut, dir_home,strlen(dir_current),&num,NULL);
WriteConsole(hStdOut,dir_searching,strlen(dir_searching),&num,NULL);
SetCurrentDirectory(dir_temp);
file_txt = FindFirstFile(lpSearchFile,&FindFileData);
if (!file_txt)
{
WriteConsole(hStdOut,file_not_found,strlen(file_not_found),&num,NULL);
}
WriteConsole(hStdOut,file_found,strlen(file_found),&num,NULL);
WriteConsole(hStdOut,FindFileData.cFileName,strlen(FindFileData.cFileName),&num,NULL);
LPSTR old_file = new CHAR[50],
new_file = new CHAR[50];
strcpy(old_file,dir_temp);
strcat(old_file,FindFileData.cFileName);
SetCurrentDirectory(dir_current);
strcpy(old_file,dir_current);
strcat(old_file,"\\");
strcat(old_file,FindFileData.cFileName);
FindClose(file_txt);
WriteConsole(hStdOut,file_new,strlen(file_new),&num,NULL);
ReadConsole(hStdIn,new_file,strlen(new_file),&num,NULL);
new_file[num-2]='\0';
strcpy(new_file,dir_current);
strcat(new_file,"\\");
strcat(new_file,FindFileData.cFileName);
*********************
CopyFile(old_file,new_file,TRUE);
SetFileAttributes(new_file,FILE_ATTRIBUTE_READONLY);
if (CopyFile(old_file,new_file,TRUE))
{
WriteConsole(hStdOut,file_copy,strlen(file_copy),&num,NULL);
}
else
{
WriteConsole(hStdOut,file_copy_error,strlen(file_copy_error),&num,NULL);
}
CreateFile(new_file,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if (CreateFile==INVALID_HANDLE_VALUE){
WriteConsole(hStdOut,"Invalid file handle",strlen("Invalid file handle"),&num,NULL);
}
if(!WriteFile (CreateFile,file_info,strlen(file_info),&num,NULL))
{WriteConsole(hStdOut,file_write_error,strlen(file_write_error),&num,NULL);}
CloseHandle(hStdIn);
CloseHandle(hStdOut);
}
[Visual C++]Проблема с копированием файла
Собственно программа уже готова. Она находит в директории с:\\Temp первый файл и расширением .txt и должна этот файл копировать в текущюю директорию, но тут почему не получается.
Проблемный кусок выделен.
Код:
а зачем 2 раза файл копировать?
Может, хоть за каким-то разом и скопируется :)