getting contents from drive letter
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: getting contents from drive letter

  1. #1
    Join Date
    Jul 2008
    Posts
    28

    getting contents from drive letter

    Hi all,
    is it possible to get the contents of a drive i.e the list of all files and folders inside the drive ?

    i have the drive letter with me.
    so please can i get some help to get all the contents inside the drive ???

    Thank You

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,605

    Re: getting contents from drive letter

    Have a look at CFileFind class and its methods.
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2008
    Posts
    28

    Re: getting contents from drive letter

    if there are any folders in the directory, how would you seek them?
    please do have a proper look at the question which says i want to list all the contents of a drive ??

    all the members also need a destination ?? without enumerating the contents how would we pass the contents to CFindFIle class?

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,605

    Re: getting contents from drive letter

    Quote Originally Posted by sgcoders View Post
    please do have a proper look at the question which says i want to list all the contents of a drive ??
    Please do have a proper look at the documentation of CFileFind class and its methods in MSDN.

    And you cannot "pass the contents" "without enumerating".
    See the example in CFileFind::IsDirectory
    Victor Nijegorodov

  5. #5
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: getting contents from drive letter

    A quick and dirty method (not necessarily recommended therefore) to get all files and folders of a drive is to using the dir /s command of the Windows command interpreter cmd and redirect the output of that command to a file.

    Code:
    // assume the drive letter is x
    system("dir /s /b x:\*.* > xxx.txt");
    std::ifstream xxx("xxx.txt");
    if (xxx)
    {
         std::string line;
         while (getline(xxx, line))
               std::cout << line << std::endl;
         xxx.close();
         remove("xxx.txt");  
    }

  6. #6
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,059

    Re: getting contents from drive letter

    Quote Originally Posted by itsmeandnobodyelse View Post
    A quick and dirty method ...
    Clear dirty.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center