使用C#创建子目录 [英] Create subdirectories using c#

查看:141
本文介绍了使用C#创建子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我正在创建Windows应用程序,其中需要将xml文件从一个目录移动到另一个目录.
问题是我想将文件移动到将根据其移动日期创建的新目录中,意味着如果文件今天被移动,则该文件将存储在MovedFolder/2012/March/15/FileName中. xml.

在此先感谢您

Hello Friends,

I am creating a windows application in which i need to move a xml file from one directory to another.
Problem is that i want to move the file into a new directory which will be created according to the date of its moving,means if the file is been moved today then the file will be stored in MovedFolder/2012/March/15/FileName.xml.

Thanks in advance

推荐答案

您是否尝试过一个非常明显的名称 ^ ]
Have you tried the very obviously named Directory.CreateDirectory[^]


CreateDirectory可以创建一系列子目录

CreateDirectory can create a sequence of subdirectories

Directory.CreateDirectory(@"c:\dir1\dir2\dir3");

将创建所有三个目录(如果尚不存在).

一点点自定义DateTime格式将为您提供所需的内容. [

will create all three directories if they don''t already exist.

A little bit of custom DateTime formatting will get you what you want. [^]

Directory.CreateDirectory(DateTime.Now.ToString(@"c:\yyyy\MMMM\dd"));



很抱歉,这完全是胡说八道,它将起作用:



sorry that was complete nonsense, this will work:

private static void CreateDirectories() {
  DateTime current = DateTime.Now;
  String name = String.Format(@"v:\{0:yyyy}\{1:MMMM}\{2:dd}", current, current, current);
  try {
    Directory.CreateDirectory(name);
  } catch (Exception e) {
    Console.WriteLine(e);
  }
}





艾伦.





Alan.


嗨..

希望这会有所帮助....

字符串路径="D:\\ MoveFolder \\" + DateTime.Now.Year.ToString()+"\\" +
DateTime.Now.ToString("MMMM")+"\\" + DateTime.Now.Day.ToString();

Directory.CreateDirectory(path);
FileStream fs = File.Create(path +"\\ Filename.xml");
hi..

hope this will help....

string path = "D:\\MoveFolder\\" + DateTime.Now.Year.ToString() + "\\" +
DateTime.Now.ToString("MMMM") + "\\" + DateTime.Now.Day.ToString();

Directory.CreateDirectory(path);
FileStream fs = File.Create(path+"\\Filename.xml");


这篇关于使用C#创建子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆