Skip to main content
gamedev.net
🔒 Locked

File/System commands?

Started by coolguy121 3 replies 400+ views
Original Post
coolguy121
coolguy121
In C++, how can I execute DOS-like commands like dir? How can I check the contents of a directory or disk drive? I''ve heard it''s possible to use system() function, but I have no idea how to use it. Please give examples or links to tutorials, thanks.
Null and Void
Null and Void
If you''re writing a program for Win32 Console (not ''real DOS'') you can use FindFirstFile (et cetera) to list all (or some) of the files and/or directories in some location. You can look in the MSDN for some information. Or (*shameless plug*) you can look at the Win32 source code behind libHFS for a working example. Specifically look at the function "hfsEnumFiles" in "winhfs.c".

[Resist Windows XP''s Invasive Production Activation Technology!]
Oluseyi
Oluseyi
You should NOT get into the habit of using system() to perform operations. There are almost always better and more portable ways to do the same thing.

Look up the header <direct.h> It''s platform-specific (DOS/Windows), but it contains several functions for working with drives and directories.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.