www.pudn.com > FTPServerClient.zip > directory.cpp
#include "directory.h"
using namespace std;
Directory::Directory() {
path = "/";
}
Directory::Directory(const string& dir) {
path = dir;
}
Directory::operator string() const {
return path;
}
void Directory::cd(const string& dir) {
if(dir=="..")
cdUp();
else if(dir!=".")
if(dir[0]=='/')
path = dir;
else {
if(path[path.length()-1]!='/') path += '/';
path += dir;
}
}
void Directory::cdUp() {
if(path=="/") return;
int slash = path.rfind('/', path.length()-2);
if(slash>0)
path.resize(slash);
else
path = "/";
}
string Directory::buildFullname(const string& prefix, const string& suffix) {
string full;
if(prefix[prefix.length()-1]=='/')
full = prefix.substr(0, prefix.length()-1);
else
full = prefix;
if(suffix[0]!='/') {
full += path;
if(full[full.length()-1]!='/') full += '/';
}
full += suffix;
return full;
}