Search code examples
c++windowstreecmdcd

Using tree Command in C++ on C://


I want to use the Windows CMD tree command in my C++ console application. My code:

system("cd c:/");
system("tree");

The problem is that the command tree will execute on the folder path where the program is running and not on C://. Is there a way to fix this?


Solution

  • You can use SetCurrentDirectory from windows.h. This page has a demonstration: http://msdn.microsoft.com/en-us/library/windows/desktop/aa363806%28v=vs.85%29.aspx