如何快速新建文件和文件夹

新建不同后缀的文件,我是用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.
 

猜你喜欢

转载自blog.csdn.net/qq_41598072/article/details/85060527