Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Interactive file system in C++


ghost's Avatar
0 0

hi, if you remember on my little prog, a virtual console (something as here rooting challenges), i am doing v2, and my teacher recommend me to do this more interactive, in my v1, i have my file system "hard-coded" into program, so if(command = rm root) then remove root, nothing else, is there any way to do this file system more interactive (e.g. user has localhost and remotehost, he can add programs from localhost to remotehost and from remotehost to localhost… he can download files etc. he can download files etc.) is there any way to do this? for example with classes maybe? i need to push in the right direction, thanks in advance for any help


ghost's Avatar
0 0

well, i have no idea how you could do that but, i would use something along the lines of this:

char host[150];
char file[150];

cin>> file;
cin.ignore();

if
( file == "..whatever.." );{
            cin>>  host;
             if
             ( host == "local" );{
put the file in local
}
else {
put the file in remote
}
}
cin.get();
}

somthing like that…………………………………………………


ghost's Avatar
0 0

Just sit down and figure out the logic of what you need to do. You need to keep track of the users, their installed programs, their filesystems… those can all be tracked in a database.

Next, you need to interpret commands… think of how a typical Linux or DOS command works. The first part is the actual command, followed by any switches, then the arguments (if any) for the command. All of those are separated by spaces, so just take the whole line input from the user and split it (by the " " character) into an array. Have a multiple conditional statement to send the program flow to separate methods for each command, passing the switches and arguments as an array argument to the method. Then, loop through the array, picking out switches and such, and have the program act differently according to what switches / arguments were used.

It's not at all an easy project, but neither is creating your own operating system. My advice is more general than anything… I haven't coded in C++ since high school, so I don't remember much that would be helpful specifically for that language.

Hope that helps.


ghost's Avatar
0 0

i know what i´ll have to do.. i know synatx of linux commands etc. etc i only need to know how to program this interactive system in c++, because as i say, i had project like this, but it is smaller, and i had all the commands and files in it "hard-coded" into program…


ghost's Avatar
0 0

dancuc wrote: Editor Snippet: "I didn't brainstorm…"

i only need to know how to program this interactive system in c++

Editor Snippet: "My previous program is nothing like this one."

The only sentence left in the quote is the important one, then. You need to learn more about C++ and use my post as a reference for the logic of the program. You are asking for advice, and I gave it to you. I'm not going to program an example system for you in any language just so you can bite my ideas off the forum.

Just brainstorm and get what you have to do on paper. That will help you get organized, and then you can tackle doing it in your language of choice.


ghost's Avatar
0 0

ok thanks to all ;)


ghost's Avatar
0 0

Maybe declare an array with each first piece of data array[0] being the path name, and every data in that be files. The only issue would be doing a folder within a folder.

Sorry if this doesn't make sense.;)


ghost's Avatar
0 0

You could do this easily with vectors and struct.

This would allow you to have as many partitions as you want, as many folders and sub folders as you want and as many files as you want.

You can even put data in those files, permissions, etc. Then you can do functions to donwload the files, delete, add files, etc.


ghost's Avatar
0 0

varreon wrote: Maybe declare an array with each first piece of data array[0] being the path name, and every data in that be files. The only issue would be doing a folder within a folder.

Not really. The main issue would be structure retention for the filesystem. You want to be able to permanently track filesystem structure and changes, which means that a temporary array won't cut it. You'll need a database, CSV file, or XML file, as the likely options.