1. 程式人生 > >如何快速新建檔案和資料夾

如何快速新建檔案和資料夾

新建不同字尾的檔案,我是用C++的程式碼做的:

#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
 
 
int main () 
{ 
	int k = 1;
	//system("mkdir d:\\output");//是在d盤下建立output資料夾
 
	//system("mkdir d:program files\\output"); //路徑若帶空格,則無法建立,要採用在路徑上加\"... \",即\"路徑\"
 
	//system("mkdir \"d:program files\\output\""); 路徑若帶空格,建立正確
 
	 system("mkdir \"output\"");//是在當前main目錄下建立output資料夾
	
	 for (;k !=4;++k)
	 {    
	stringstream ss;//會自動析構,每一次迴圈會清空ss裡面內容
 
	ss <<"output\\" <<  k << ".txt"; 
		
		 cout << ss.str() <<endl; //這裡每個文字路徑顯示的是output\k.txt,這是真實的路徑顯示形式 (不是output\\k.txt)
		
		 ofstream fout(ss.str());
		   
		 fout <<"1";
		
	
		 fout.close();
	 }
	 
	system("pause");
	return 0;
}  

新建資料夾我用cmd實現的:

Set Up a New Folder: To set up new folders using command prompt, use the command "md" (stands for "make directory"). With this command you can create one or several folders. To create a separate folder for each month, you can follow the following format:

md 01_January 02_February 03_March 04_April 05_May 06_June 07_July 08_August 09_September 10_October 11_November 12_December

When you press the Enter key, you won't see anything just yet. However, after you add the "dir" command and press Enter, the command prompt window will display the created folders.