使用C#创建文件夹并将文件移入其中 [英] Create folder and move files into it using C#

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

问题描述



我在这个aaaa文件夹中有一个目录C:\ Ajith \ aaaa我有两个pdf文件。我需要创建两个文件夹'A'和'b'并将每个.pdf文件移动到它们中。我怎样才能做到这一点。有人帮忙提前使用c $ .net ..谢谢。

Hi,
I have a directory "C:\Ajith\aaaa" inside this aaaa folder i have two pdf files. I need to create two folders as 'A' and 'b' and move each .pdf files into them. how can i do this. pls somebody help using c$ .net ..thanks in advance.

推荐答案

.net ..提前谢谢。
.net ..thanks in advance.






请参阅此代码作为示例:

Hi,

see this code as an example:
string root = "C:\\Ajith\\aaaa";
System.IO.Directory.CreateDirectory(root + "\\A");
System.IO.Directory.CreateDirectory(root + "\\B");
System.IO.File.Move(root + "\\test1.pdf", root + "\\A\\test1.pdf");
System.IO.File.Move(root + "\\test2.pdf", root + "\\B\\test2.pdf");



要获取目录中所有文件的列表,您可以使用以下代码:


To get the list of all files in your directory you could use this code:

string [] files = System.IO.Directory.GetFiles(root);






请参阅以下链接,它可以帮助您创建文件夹。



http://www.venkateswarlu.co.in/articles/DotNet/Creat_Delete_Folder.aspx [ ^ ]



和看到以下链接可帮助您将文件从一个文件夹复制到另一个文件夹。



<小时EF = http://msdn.microsoft.com/en-us/library/cc148994.aspx> http://msdn.microsoft.com/en-us/library/cc148994.aspx [<一个href =http://msdn.microsoft.com/en-us/library/cc148994.aspxtarget =_ blanktitle =新窗口> ^ ]

< a href =http://www.dreamincode.net/forums/topic/113204-how-to-copy-a-file-from-place-to-another/> http://www.dreamincode.net/ forums / topic / 113204-how-to-copy-a-file-from-place-to-another / [ ^ ]



谢谢,

Viprat
Hi,

See the below link which help you how to create folder.

http://www.venkateswarlu.co.in/articles/DotNet/Creat_Delete_Folder.aspx[^]

and see the below link which help you to copy file from one folder to another folder.

http://msdn.microsoft.com/en-us/library/cc148994.aspx[^]
http://www.dreamincode.net/forums/topic/113204-how-to-copy-a-file-from-place-to-another/[^]

Thanks,
Viprat


这篇关于使用C#创建文件夹并将文件移入其中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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