int watch_fd;
 };
 
-int torrent_add(struct torrent*,struct file*);
+int torrent_add(struct torrent*,const char*,struct file*);
 void torrent_free(struct torrent*);
 int torrent_init(struct torrent**,const char*,const char*);
 
 
        int watch_fd;
 };
 
-int tree_add(struct tree*,struct file*);
+int tree_add(struct tree*,const char*,struct file*);
 void tree_entry_free(struct tree_entry*);
 int tree_entry_init(struct tree_entry**, struct file*);
 void tree_free(struct tree*);
 
        return 1;
 }
 
-static struct file *get_next() {
-       struct file *p;
-       while(add_queue_index<add_queue->size) {
-               p = add_queue->map[add_queue_index];
-               add_queue_index++;
+static int add_find_all(struct torrent *p) {
+       log_info(ADD_MESSAGE_ADDING_TORRENT,p->root,p->name);
+       current_torrent = p;
 
-               if(p!=NULL) { return p; }
+       if(ftw(p->root,&ftw_helper,64)<0) {
+               perror("ftw");
+               return -1;
        }
 
-       return NULL;
+       return 1;
 }
 
 static void *add_hash(void *unused) {
        return NULL;
 }
 
-
-static int add_find_all(struct torrent *p) {
-       log_info(ADD_MESSAGE_ADDING_TORRENT,p->root,p->name);
-       current_torrent = p;
-
-       if(ftw(p->root,&ftw_helper,64)<0) {
-               perror("ftw");
-               return -1;
-       }
-
-       return 1;
-}
-
 static int add_queue_resize(size_t new_size) {
        struct file *p;
        struct hash_map *new, *old;
 
 static int ftw_helper(const char *path, const struct stat *st, int typeflag) {
        struct file *to_add;
+       const char *p;
 
        if(typeflag!=FTW_F) { return 0; }
        switch(global_options.file_filter) {
        }
 
        if(file_init(&to_add,path)<0) { return -1; }
-
        if(add_to_queue(to_add)<0) { return -1; }
 
-       if(torrent_add(current_torrent,to_add)<0) { return -1; }
+       p = strstr(path,current_torrent->root);
+       if((p!=NULL)&&(p==path)) {
+               p += strlen(current_torrent->root);
+       } else {
+               p = path;
+       }
+
+       if(torrent_add(current_torrent,p,to_add)<0) { return -1; }
 
        return 0;
 }
+
+static struct file *get_next() {
+       struct file *p;
+       while(add_queue_index<add_queue->size) {
+               p = add_queue->map[add_queue_index];
+               add_queue_index++;
+
+               if(p!=NULL) { return p; }
+       }
+
+       return NULL;
+}
 
 #include<torrent.h>
 
-struct torrent **torrents;
-
 static int torrent_add_file(struct torrent *p, struct file *f);
 
-int torrent_add(struct torrent *p, struct file *f) {
+int torrent_add(struct torrent *p, const char *path, struct file *f) {
        if(NULL==p) { return -1; }
        if(NULL==f) { return -1; }
+       if(NULL==path) { return -1; }
 
-       if(tree_add(p->tree,f)<0) { return -1; }
+       if(tree_add(p->tree,path,f)<0) { return -1; }
        if(torrent_add_file(p,f)<0) { return -1; }
 
        return 1;
 
 static struct tree* tree_add_directory(struct tree*,const char*);
 static int tree_add_file(struct tree*,struct file*);
 
-int tree_add(struct tree *root, struct file *to_add) {
+int tree_add(struct tree *root, const char *path, struct file *to_add) {
        char *str, *p, *prev;
        struct tree *tree;
 
        if(NULL==root) { return -1; }
        if(NULL==to_add) { return -1; }
+       if((NULL==path)||(strlen(path)<=0)) { return -1; }
 
        tree = root;
 
-       str = strdup(to_add->path);
+       str = strdup(path);
        if(NULL==str) { return -1; }
 
        prev = NULL;