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);
}

Ref:http://stackoverflow.com/questions/6925561/whats-the-easiest-way-to-ensure-folder-exist-before-i-do-a-file-move

move file create directory.的更多相关文章

  1. Git异常:fatal: could not create work tree dir 'XXX': No such file or directory

    GitHub实战系列汇总:http://www.cnblogs.com/dunitian/p/5038719.html ———————————————————————————————————————— ...

  2. 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 ...

  3. 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 ...

  4. C# IO流 File.Exists,Directory.Exists, File.Create,Directory.CreateDirectory

    void Start() { CreateDirectory(); CreateFile(); } //平台的路径(封装起来的一个属性,这不是一个方法) public string path { ge ...

  5. mkdir: Cannot create directory /file. Name node is in safe mode.

    刚刚在hadoop想创建一个目录的时候,发现报错了 具体信息如下: [hadoop@mini1 hadoop-2.6.4]$ hadoop fs -mkdir /file mkdir: Cannot ...

  6. 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 ...

  7. C#基础精华04(文件流,文件操作,File、Directory、Path,Directory)

    文件流 FileStream  可读可写  大文件  释放 StreamReader 读取   释放 StreamWriter 写入   释放 using 中释放 File 可读可写  小文件 操作文 ...

  8. python文件和文件夹訪问File and Directory Access

    http://blog.csdn.net/pipisorry/article/details/47907589 os.path - Common pathname manipulations 都是和路 ...

  9. File、Directory、Path

    File.Directory.Path https://blog.csdn.net/xiaouncle/article/details/52050577 File.Directory.Path是实际开 ...

随机推荐

  1. Party

    hdu3062:http://acm.hdu.edu.cn/showproblem.php?pid=3062 题意:中文题. 题解:很明显的2-sat.然后要深刻理解命题和逆否命题.如这一题,c1,c ...

  2. Match & Catch

    Codeforces Round #244 (Div. 2) D:http://codeforces.com/contest/427/problem/D 题意:给你两个串,让你找一个最小的串,并且这个 ...

  3. SQL SELECT基本语句结构

    (1)SELECT select_list (2) FROM table_list (3)   WHERE search_conditions     GROUP BY group_by_list   ...

  4. Class.forName()的理解

    转自:http://blog.csdn.net/yanwushu/article/details/7574713 使用jdbc方式连接数据库时会使用一句代码Class.forName(String c ...

  5. linux No manual entry for

    我的博客:www.while0.com 原来除了安装man,还要安装man-pages. yum install man -y yum install man-pages -y

  6. Android数据存储之文件存储

    首先给大家介绍使用文件如何对数据进行存储,Activity提供了openFileOutput()方法可以用于把数据输出到文件中,具体的实现过程与在J2SE环境中保存数据到文件中是一样的. public ...

  7. 2016年QS亚洲大学排行榜

    2016年QS亚洲大学排行榜 人民网北京6月14日电 (记者 郝孟佳)今天,全球高等教育分析机构QS全球教育集团发布了2016年QS亚洲大学排名.清华大学在亚洲20强大学中进步最大,比去年提升6名,上 ...

  8. delphi编写winsocket的流程

    delphi编写winsocket的流程 1.在窗体创建的时候启用动态连接库(引用winsock)    var  aWSAData:TWSAData;    if WSAStartup($0101, ...

  9. 在Eclipse中格式化Android代码

    我们用Eclipse做Android开发的时候,可以导入Google提供的profile文件,这样每次"Ctrl+Shift+F"的时候,IDE就能够按照官方的规范来进行代码格式化 ...

  10. net user命令

    net user net user 用户名 net user 用户名 密码 /add net user 用户名 /del net localgroup administrators net local ...