bool Directory::paste(std::string newpath) { //If we have not read the directory's contents //previously, read them now: if(_files.size() == 0) read(); //Creates a new directory in the new path: std::string path = newpath + getName(); if(mkdir(path.c_str(), _attr->st_mode) != 0) return false; //Copies the contents of the directory to //the newly created directory: for(unsigned int i = 0; i < _files.size(); i++) if(_files[i]->getName() != "../") if(! _files[i]->paste(path)) return false; //If the file was set to cut, delete the contents //and then delete the directory: if(_isCut) if(! deletef()) return false; return true; }
//Creates a copy of the file in the passed location: bool File::paste(std::string newpath) { //Opens an input file: std::ifstream in(_path.c_str(), std::ios::binary); //Opens an output file: std::string path = newpath + getName(); std::ofstream out(path.c_str(), std::ios::binary); //If either cannot be opened: if((! in) || (! out)) return false; //Writes the input file to the output file: out << in.rdbuf(); //Closes the files: in.close(); out.close(); //If we are cutting the file, delete the original: if(_isCut) if(! deletef()) return false; //Get the original's permission bits: mode_t permission = _attr->st_mode; //Attempts to write the original permission bits: if(chmod(path.c_str(), permission) != 0) return false; return true; }
void deletep(char *s,char *sss) { char s1[80],s3[80],s4[80],s2[80]; int x,k=0,k1=0,i,j; strcpy(s1,s); strcat(s1,sss); strcpy(s3,s1); strcat(s3,"\\*.*"); struct ffblk full; x=findfirst(s3,&full,0); if (x==0) { strcat(s1,"\\"); struct ffblk full; x=findfirst(s3,&full,0); while (!x) { deletef(s1,full.ff_name); x=findnext(&full); } } strcpy(s1,s); strcat(s1,sss); strcpy(s4,s1); strcat(s4,"\\*."); struct ffblk full1; x=findfirst(s4,&full1,0x10); while (!x) { x=findnext(&full1); k++; } if (k>2) { strcat(s1,"\\"); struct ffblk full1; x=findfirst(s4,&full1,0x10); while (!x) { if (full1.ff_name[0]!='.') { cout<<"1 "<<endl; puts(s1); getch(); deletep(s1,full1.ff_name); } x=findnext(&full1); } } else { strcpy(s1,s); strcat(s1,sss); x=rmdir(s1); cout<<"Rem "<<endl; puts(s1); strcpy(s1,s); strcpy(s4,s1); strcat(s4,"*."); struct ffblk full1; x=findfirst(s4,&full1,0x10); k=0; while (!x) { x=findnext(&full1); k++; } if (k>2) { return; cout<<"Sdelan vozvrat"<<endl; } else { k=0; strcpy(s1,""); strcpy(s2,""); for (i=0; s[i]!='\0'; i++) if (s[i]=='\\') k++; k--; for (i=0; i<k; i++) { for (j=0; s[j]!='\\'; j++); strncpy(s1,s,j+1); s1[j+1]='\0'; strcat(s2,s1); strcpy(s,&s[j+1]); } for(i=0; s[i]!='\\'; i++); s[i]='\0'; cout<<"2 "<<endl; puts(s2); getch(); if (strcmp(so,s2)==0) return; deletep(s2,s); } } }