# C/C++/MSVC programmers: how do I open and make use of file directories?

**URL:** <https://boards.straightdope.com/t/c-c-msvc-programmers-how-do-i-open-and-make-use-of-file-directories/348819>\
**Category:** Factual Questions\
**Created:** [March 17, 2006, 10:37pm UTC](https://boards.straightdope.com/t/c-c-msvc-programmers-how-do-i-open-and-make-use-of-file-directories/348819 "2006-03-17T22:37:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![VunderBob](https://avatars.discourse-cdn.com/v4/letter/v/839c29/32.png) [@VunderBob](https://boards.straightdope.com/u/VunderBob)\
**Post date:** [March 17, 2006, 10:37pm UTC](https://boards.straightdope.com/t/c-c-msvc-programmers-how-do-i-open-and-make-use-of-file-directories/348819/1 "2006-03-17T22:37:42Z")

</div>

I want to write a quick application for home use that selects a random MP3 file from a directory on my PC, and copy it to my MP3 player. I think I want to open the directory itself to extract the file names and file sizes. I know I could do what I want by using system() and some DOS commands to write the data I want to a text file, but that’s too kludgey and too easy.

I’d like to use C/C++/MSVC functions to open the DIR directly, but I couldn’t find anything in the Visual Studio documentation under ‘file’ or ‘directory’ to support this. What should I look for?

---

<div class="post-metadata">

**Author:** ![griffin1977](https://avatars.discourse-cdn.com/v4/letter/g/977dab/32.png) [@griffin1977](https://boards.straightdope.com/u/griffin1977)\
**Post date:** [March 17, 2006, 11:09pm UTC](https://boards.straightdope.com/t/c-c-msvc-programmers-how-do-i-open-and-make-use-of-file-directories/348819/2 "2006-03-17T23:09:44Z")

</div>

> [@VunderBob](#):
>
> I want to write a quick application for home use that selects a random MP3 file from a directory on my PC, and copy it to my MP3 player. I think I want to open the directory itself to extract the file names and file sizes. I know I could do what I want by using system() and some DOS commands to write the data I want to a text file, but that’s too kludgey and too easy.
> 
> I’d like to use C/C++/MSVC functions to open the DIR directly, but I couldn’t find anything in the Visual Studio documentation under ‘file’ or ‘directory’ to support this. What should I look for?

I beieive FindFirstFile/FindNextFile in the PlatformSDK can be used to do this kind of thing.
