Thread: How to navigate

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    241

    How to navigate

    I'm trying to make kindof a command prompt thing where we can do the same stuff in this as the command prompt. Can anybody tell me how I can assign drives like make it goto C:\ and like navigate through all the files in c?
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        char com[256];
        begin:
            cout<<"Please input a command.\n";
            cin>>com;
            system(com);
        goto begin;
        return 1;
    }
    Yeah I'm a real beginner and I dont really know alot so any help (or cristsism) will be helpful.

  2. #2
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    thanks now just to get that into my code and ill be done... hopefully, will ti stay in thta directory?

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    I dont know how to merge the two together

  5. #5
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    I think you're jumping the gun, if you're a beginner I suggest you do something easier... learn more
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  6. #6
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    yes this only works for windows.

    If you're using windows try posting the previous code you had (and a description of what you want it to do) and perhaps someone may be able to help you merge them together.


    Alternatively, if your code is too large to post, try testing small parts bit by bit. See what works and what doesn't.

  7. #7
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    I know, but I just want to make this so then I have something similar to a command prompt to use at school my original code will execute regedit and such but when i try taskman it doesnt give me an error message, like it goes though but the task manager doesnt come up

  8. #8
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    wow and that code whats in the link i did C:\windows and its listing like everything..in the drive or osmething its just goin on and on

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    If you're a beginner you should learn how to use a loop. The goto command is not a good habit to get into.

  10. #10
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    How would I loop it?

  11. #11
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    this is what i am getting for the directory part of it but it keeps xing out right away
    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    int main()
    {
        WIN32_FIND_DATA FindFileData;
        HANDLE hFind = INVALID_HANDLE_VALUE;
        char DirSpec[MAX_PATH];
        char file[256];
        cin>>file;
        cin.get(DirSpec, MAX_PATH);
        strncat (DirSpec, "\\*", 3);
        hFind = FindFirstFile(DirSpec, &FindFileData);
        cout<<FindFileData.cFileName<<"\n";
        while(FindNextFile(hFind, &FindFileData) != 0)
    	{
    	cout<<FindFileData.cFileName<<"\n";
    	}
    
    FindClose(hFind);
        cin.get();
        return 1;
    }
    and it doesnt save where it went like if i said C:\windows i want it to stay there and wait for like commands and such until i do like cd ..\..\

  12. #12
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    hmm it sounds to me, (although I could be mistaken), you are trying to emulate the *command prompt* in c++.

    That in itself is a mammoth task. The code provided merely, allows you to view the contents of a directory, nothing else such as copy files or other stuff you would do in the *command prompt*.


    What's wrong with actually using the *command prompt* anyway?

    However, if you are dead set on using this in c++ your best bet is to try using *system*.

    For example, in *command prompt* to view the memory you would type.

    >>mem

    To emulate this, and all other command prompt commands, you might do:

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
       system("mem");
       system("pause");
    }
    However,using system has it's draw backs in itself as you are probably well aware of, and the code is compiler and operating system dependent.

  13. #13
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Quote Originally Posted by treenef
    hmm it sounds to me, (although I could be mistaken), you are trying to emulate the *command prompt* in c++.

    That in itself is a mammoth task. The code provided merely, allows you to view the contents of a directory, nothing else such as copy files or other stuff you would do in the *command prompt*.


    What's wrong with actually using the *command prompt* anyway?

    However, if you are dead set on using this in c++ your best bet is to try using *system*.

    For example, in *command prompt* to view the memory you would type.

    >>mem

    To emulate this, and all other command prompt commands, you might do:

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
       system("mem");
       system("pause");
    }
    However,using system has it's draw backs in itself as you are probably well aware of, and the code is compiler and operating system dependent.
    yeah i know that system thing i had it inmy orig prog that just was a simple run program of sorts
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        char com[256];
        begin:
            cout<<"Please input a command.\n";
            cin>>com;
            system(com);
        goto begin;
        return 1;
    }
    but i tried it at school and it said unc (or something like that) paths are not supported

Popular pages Recent additions subscribe to a feed