move file create directory.
If we want to move file to the directory that does not exist,and if we perform a File.Move,it will result return an error shows that 'The path is not exist'.
So,we have to create a new directory using System.IO.Directory.CreateDirectory.
Here is an example:
string path = txt_path.Text.Trim(); //Root of the path that contains files to be move.
System.IO.DirectoryInfo dirRoot = new System.IO.DirectoryInfo(path);
if (!dirRoot.Exists) {
MessageBox.Show("The directory is not exist!");
return;
}
System.IO.FileInfo[] files = dirRoot.GetFiles();
foreach (var file in files) { //Iterate create new directories.
System.IO.DirectoryInfo dir = System.IO.Directory.CreateDirectory(file.DirectoryName + "\\" + System.IO.Path.GetFileNameWithoutExtension(file.Name));
file.MoveTo(dir.FullName + "\\" + file.Name);
}
move file create directory.的更多相关文章
- Git异常:fatal: could not create work tree dir 'XXX': No such file or directory
GitHub实战系列汇总:http://www.cnblogs.com/dunitian/p/5038719.html ———————————————————————————————————————— ...
- linux,安装软件报错cannot create regular file '/usr/local/man/man1': No such file or directory
make install时报错,如下 install: cannot create regular file '/usr/local/man/man1': No such file or direct ...
- adb pull 报错处理:adb: error: cannot create file/directory 'E:\': No such file or directory
adb pull /sdcard/1.txt e:/ 报错:adb: error: cannot create file/directory 'E:\': No such file or direct ...
- C# IO流 File.Exists,Directory.Exists, File.Create,Directory.CreateDirectory
void Start() { CreateDirectory(); CreateFile(); } //平台的路径(封装起来的一个属性,这不是一个方法) public string path { ge ...
- mkdir: Cannot create directory /file. Name node is in safe mode.
刚刚在hadoop想创建一个目录的时候,发现报错了 具体信息如下: [hadoop@mini1 hadoop-2.6.4]$ hadoop fs -mkdir /file mkdir: Cannot ...
- opencv c++安装踩坑记录 file cannot create directory: /usr/local/include/opencv2. Maybe need administrative privileges
前言 最近深度学习Ultra-Fast-Lane-Detection/INSTALL.md at master · cfzd/Ultra-Fast-Lane-Detection (github.com ...
- C#基础精华04(文件流,文件操作,File、Directory、Path,Directory)
文件流 FileStream 可读可写 大文件 释放 StreamReader 读取 释放 StreamWriter 写入 释放 using 中释放 File 可读可写 小文件 操作文 ...
- python文件和文件夹訪问File and Directory Access
http://blog.csdn.net/pipisorry/article/details/47907589 os.path - Common pathname manipulations 都是和路 ...
- File、Directory、Path
File.Directory.Path https://blog.csdn.net/xiaouncle/article/details/52050577 File.Directory.Path是实际开 ...
随机推荐
- Watch gcc at ubuntu 12,See ELF file header
first write article at my ubuntu 12. ELF is very important file format.
- 一个简单的C#获取Session、设置Session类文件
一个简单的C#获取Session.设置Session类文件,本类主要实现大家最常用的两个功能: 1.GetSession(string name)根据session名获取session对象: 2.Se ...
- Astyle:代码格式化工具简明指南
astyle是一个我自己常用的开放源码工具.它可以方便的将程序代码格式化成自己想要的样式而不必人工修改.本来嘛,作为高等生物应该优先去做一些智慧的事情,而不是把时间消耗在机器可以完美完成的事情上. 想 ...
- highestAvailable比较灵活,毕竟大多数功能不需要系统最高权限(四种方法:屏蔽UAC,右键以管理员身份运行,增加manisfest,制作数字证书)
打开VS2005.VS2008.VS2010工程,查看工程文件夹中的Properties文件夹下是否有app.manifest这个文件:如没有,按如下方式创建:鼠标右击工程在菜单中选择“属性”,点击工 ...
- ServletContextListener作用(转)
ServletContext 被 Servlet 程序用来与 Web 容器通信.例如写日志,转发请求.每一个 Web 应用程序含有一个Context,被Web应用内的各个程序共享.因为Context可 ...
- Java中类Exchaner浅析
Exchaner用于实现两个人之间的数据交换,每个人在完成一定的事物后想与对方交换数据,第一个先拿出数据的人将一直等待第二个人拿着数据到来时,才能彼此交换数据. 张孝祥老师在讲解Exchaner时的比 ...
- (转载)浅谈javascript的分号
(转载)http://www.blueidea.com/tech/web/2009/7261.asp javascript的分号代表语句的结束符,但由于javascript具有分号自动插入规则,所以它 ...
- tomcat 配置内存相关
今天早上 ,tomcat 网站页面上出现报错问题.最后还是一位同事解决的,这里记录一下. 1.看了一下页面,他说是内存溢出. 首先找到 双击 Tomw.exe 出现如下图 然后需要配置堆栈大小
- shadowgun的飘扬旗帜shader
MADFINGER-Lightmap-Unlit-Wind用于模拟布料和树被风吹的弯曲摆动效果 这个来自于<GPU GEMS 3>中的 “Chapter 16 Vegetation Pro ...
- hdoj 1285 确定比赛名次【拓扑排序】
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...