why does the following recursive directory creation fail?
i have posted this same question on stackoverflow and i got as far as shown. But still i have some errors(synactical and logical) which i couldn’t solve at all.
May be i can get some help here;
i expect to have more than one million files with unique names. I have been told that if i put all this files in one or two directories the search speed for these files will be extremely slow. So i have come up with the following directory architecture.
I want the directory structure to branch out with 10 sub directories and the level of the sub directories will be 4. because the file names are guaranteed to be unique i want to use these file names to make hashes which can be used to put the file in a directory and also later to find it. The random hash values will make a directory to have,approximately, 1,000 files.
so if F is root directory then inserting or searching for a file will have to go through these steps:
I want to use numbers from 0-9 as directory names
h=hash(filename)
sprintf(filepath,“f//%d//%d//%d//%d//.txt”,h,h,h,h);
HOW DO I CREATE THESE DIRECTORIES?
EDIT:
All the files are text files. The program will be distributed to many people in order to collect information for a research. So tt is important that these files are created like this.
- #include<iostream>
- #include<stdlib.h>
- #include<windows.h>
- #include<stdio.h>
- void make_dir(int depth, char *dir) {
- if (depth < 4) {
- CreateDirectoryA (dir,NULL);
- for (int i = 0; i < 10; i++) {
- char *sdir= (char*)malloc(strlen(dir+10)); // XXX 10?
- strcpy(sdir, dir);
- printf("%s\n", sdir);
- CreateDirectoryA(sdir,NULL);
- make_dir(depth + 1, sdir);
- free(sdir);
- }
- }
- }
- int main()
- {
- make_dir(0,"dir");
- return 1;
- }
1 reply
You must log in to post a reply. Not a member yet? Register here!


