怎么获取文件夹下各个子文件夹的名称

luoyiyong 2011-02-16 12:16:28
用vb查找文件夹并移动

我是刚学的vb,希望高手能指点一下。我举个例子表达我的问题吧。e盘里有个叫work的文件夹,里面有许多子文件夹,这些子文件夹的名称是按日期和类别命名的,比如有2011012189,2011012253,2011021101,2011021102,2011021201,2011021202,2011021203,……等等,前四位是年接着的两位是月再接着的两位是日,最后的几位是类别之类的,问题是我要将2月份的文件夹移动到e盘的一个新建叫201002的文件夹里,我要怎么实现呢?
我现在遇到的问题是不知道怎么读取work文件夹下的各个子文件夹的名字。
...全文
254 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xixihaha_2011_098 2011-02-16
  • 打赏
  • 举报
回复

#region 遍历指定目录
/// <summary>
/// 遍历指定目录
/// </summary>
/// <param name="path"></param>
private void getDirectories(string path)
{
try
{
string[] fileNames = Directory.GetFiles(path);
string[] directories = Directory.GetDirectories(path);
string tempstr = "";
foreach (string file in fileNames)
{

tempstr = file.Substring(file.LastIndexOf(@"\") + 1);
Console.WriteLine("Filename:{0} ", tempstr);

}
foreach (string dir in directories)
{
Console.WriteLine("Directoriesname:{0} ", dir);
getDirectories(dir);
}
}
catch (Exception ce)
{
throw (ce);
}
}
#endregion
richnaly 2011-02-16
  • 打赏
  • 举报
回复
参考msdn:http://msdn.microsoft.com/en-us/library/s7xk2b58.aspx#Y900
wuyq11 2011-02-16
  • 打赏
  • 举报
回复
Public Sub FindFile(dir__1 As String)
Dim Dir__2 As New DirectoryInfo(dir__1)
For Each d As DirectoryInfo In Dir__2.GetDirectories()
FindFile(Dir__2 + d.ToString() + "\")
listBox1.Items.Add(Dir__2 + d.ToString() + "\")
Next
End Sub
Tosp2012 2011-02-16
  • 打赏
  • 举报
回复
遍歷目錄下的所有目錄及文件
Public Sub FindFile(ByVal dir1 As String)
Dim Dir2 As New DirectoryInfo(dir1)

Try
For Each d As DirectoryInfo In Dir2.GetDirectories()
FindFile(Dir2.ToString & "\" & d.ToString)

Next
For Each f As FileInfo In Dir2.GetFiles("*.*")
MessageBox.Show(f.ToString)
Next
Catch e As Exception
MessageBox.Show(e.Message)
End Try
End Sub
宝_爸 2011-02-16
  • 打赏
  • 举报
回复
枚举一个目录下的所有目录

' Make a reference to a directory.
Dim di As New DirectoryInfo("c:\")
' Get a reference to each directory in that directory.
Dim diArr As DirectoryInfo() = di.GetDirectories()
' Display the names of the directories.
Dim dri As DirectoryInfo
For Each dri In diArr
Console.WriteLine(dri.Name)
Next dri

参考msdn:
http://msdn.microsoft.com/en-us/library/s7xk2b58.aspx#Y900

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧