遞歸創建目錄

#include <windows.h>
#include <stdio.h>

void create(int n)
{
	int i;
	char path[MAX_PATH];
	if(n > 10)
		return;
	for(i = 1; i <= 10; ++i)
	{
		sprintf(path, "%d", i);
		CreateDirectory(path, NULL);
		SetCurrentDirectory(path);
		create(n + 1);
		SetCurrentDirectory("..\\");
	}
}

int main(int argc, char *argv[])
{
	SetCurrentDirectory("D:\\Test");
	create(1);
	
	return 0;
}

堆棧溢出了
發佈了24 篇原創文章 · 獲贊 4 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章