#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
void vReplaceAll(string &path);
void vCleanPath(string &path);
bool bCopyFile(string from,string to);
int main(int argc, char *argv[])
{
string szStandartPath, szLine;
char path[256];
cout<<"paste standard path"<<endl;
getline(cin,szStandartPath);
string pathWrite;
cout<<"paste path to write"<<endl;
getline(cin,pathWrite);
for(int i = 1;i<argc;i++){
FILE * fp;
if((fp = fopen(argv[i],"r")) == NULL){
continue;
}
while(!feof(fp)){
fgets(path,255,fp);
if(path[0] == ';' || path[0] == '/'){
continue;
}
szLine = (LPCTSTR)path;
vReplaceAll(szLine);
string tmp = szStandartPath + "\\" + szLine;
string tmp2 = pathWrite + "\\" + szLine;
string command = "mkdir \""+ tmp2;
vCleanPath(command);
command += "\"";
system(command.c_str());
bCopyFile(tmp,tmp2);
/*command = "copy \"" + tmp + "\" \"" + tmp2+ "\"";
system(command.c_str());*/
}
fclose(fp);
}
system("PAUSE");
return EXIT_SUCCESS;
}
void vReplaceAll(string &path){
for(int i = 0;i<path.length();i++){
if(path[i] == '/'){
path[i] = '\\';
}
}
}
void vCleanPath(string &path){
size_t found;
found=path.find_last_of("\\");
path = path.substr(0,found);
}
bool opyFile(string from,string to){
FILE * fp = fopen(from.c_str(),"rb");
FILE * fp2 = fopen(to.c_str(),"wb");
if(fp == NULL || fp2 == NULL){
if(fp == NULL){
cout<<"czytanie"<<endl;
}
if(fp2 == NULL){
cout<<"zapisywanie"<<endl;
}
return false;
}
long lSize;
char * buffer;
size_t result;
fseek (fp , 0 , SEEK_END);
lSize = ftell (fp);
rewind (fp);
buffer = (char*) malloc (sizeof(char)*lSize);
if (buffer == NULL){
fclose(fp);
fclose(fp2);
free (buffer);
return false;
}
result = fread (buffer,1,lSize,fp);
if (result != lSize){
fclose(fp);
fclose(fp2);
free (buffer);
return false;
}
fwrite(buffer,1,sizeof(buffer),fp2);
fclose(fp);
fclose(fp2);
free (buffer);
return true;
}
nie mam pojecia dlaczego ale program nie chce otworzyc pliku do skopiowania fopen dla fp zwraca NULL