请问pb怎么遍历文件夹(包括子文件夹)

xhzlhc 2012-11-26 01:16:59
我做了个循环函数不得行
参数是 powerobject ap_listbox ; string as_path_t
lb_files_o 是实例变量

long i
ListBox lb_files_t
lb_files_t = ap_listbox
lb_files_o.reset()


if lb_files_t.totalitems() > 0 then
for i = 1 to lb_files_t.totalitems()
if lb_files_t.text(i) = '[..]' then continue
if pos(lb_files_t.text(i), '[') = 1 then
as_path_t = as_path_t + '\' + mid(lb_files_t.text(i),2,len(lb_files_t.text(i)) - 2) +"\*.*"
lb_files_o.dirList(as_path_t , 16)
wf_dirlist(lb_files_o,as_path_t)
else
lb_files1.addItem(lb_files_t.text(i))
end if
next
end if

...全文
628 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
A啦Dbit 2012-11-26
  • 打赏
  • 举报
回复
先将每个dirlist存入数组,再遍历下一下列表 可以考虑写个递归函数
xhzlhc 2012-11-26
  • 打赏
  • 举报
回复
我估计是传值问题 但是没跟出来
xuam 2012-11-26
  • 打赏
  • 举报
回复
DirList()就可以啊 你查查这个函数的用法
zlf19810306 2012-11-26
  • 打赏
  • 举报
回复
用listbox控件或着 win32 api FindFirstFile
可以轻松给图片加文字水印 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.IO; namespace WindowsApplication7 { public partial class FrmAddWave : Form { public FrmAddWave() { InitializeComponent(); } private void MakeWaterMark(string IconImg) { //定义输出位图 Bitmap bmp = new Bitmap(1000, 700); //定义绘图对象 Graphics g = Graphics.FromImage(bmp); //描述绘图矩形区域 Rectangle newRect = new Rectangle(0, 0, 1000, 700); //设置背景色 g.FillRectangle(new SolidBrush(Color.White), newRect); //获取要生成水印的图片 Bitmap newBitmap = new Bitmap(IconImg); g.DrawImage(newBitmap, 16, 16); //定义水印字的字体 Font font = new Font( "Arial", 12, FontStyle.Bold ); //定义水印字的格式刷 LinearGradientBrush brush = new LinearGradientBrush( new Rectangle(600, 600, 71, 23), Color.Red, Color.Blue, 30f, true ); //给照片打上水印 g.DrawString("copyright by test. " + System.DateTime.Now.ToShortDateString(), font, brush, 0, 0); //保存为新的输出图片 System.IO.MemoryStream ms = new System.IO.MemoryStream(); bmp.Save(@"c:\a1.jpg", ImageFormat.Jpeg); ////输出图片 //Response.ClearContent(); //Response.ContentType = "image/jpeg"; //Response.BinaryWrite(ms.ToArray()); } private void button1_Click(object sender, EventArgs e) { string strsavepath = txtsavepath.Text.ToString(); string strfilepath =textBox1.Text; if (textBox2.Text.Trim() == "") { MessageBox.Show("请输入要显示的文字"); textBox2.Focus(); return; } if (textBox1.Text.Trim() == "") { MessageBox.Show("请选择要处理的图片路径,图片必须是JPG格式"); return; } if (txtsavepath.Text.Trim() == "") { MessageBox.Show("请选择处理后的图片保存路径"); return; } if (textBox1.Text == strsavepath) { MessageBox.Show("处理后的图片保存目录不能和原目录相同"); txtsavepath.Text = ""; return ; } try { string[] font1 = txtfont.Text.Split(','); DirectoryInfo TheFolder = new DirectoryInfo(textBox1.Text); //遍历文件夹 int count = TheFolder.GetFiles().Length; int scount = 1; if (count > 0) { pb1.Maximum = count; pb1.Minimum = 1; pb1.Visible = true; } //遍历文件 foreach (FileInfo NextFile in TheFolder.GetFiles()) { pb1.Value = scount; string[] p1 = NextFile.Name.ToString().Split('.'); if (p1[1].ToString().ToLower() == "jpg" || p1[1] == "jpeg") { Makewatermark(NextFile.FullName, strsavepath + "\\" + NextFile.Name.ToString(), textBox2.Text, font1[0].ToString(), float.Parse(font1[1])); } scount++; } MessageBox.Show("处理完成!"); pb1.Visible = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void Makewatermark(string FilePath, string SavePath, string watermarkText,string fontname,float fontsize) { try { System.Drawing.Image image = System.Drawing.Image.FromFile(FilePath); int x = image.Width; int y = image.Height; Graphics g = Graphics.FromImage(image); g.DrawImage(image, 0, 0, image.Width, image.Height); Font f = new Font(fontname, fontsize ); Brush b = new SolidBrush(Color.Red ); string addText = watermarkText.Trim(); //g.DrawString(addText, f, b, x - 500, y - 50); g.DrawString(addText, f, b, x /4, y /2); g.Dispose(); image.Save(SavePath); image.Dispose(); //if (File.Exists(SavePath)) //{ // File.Delete(SavePath); //} } catch (Exception ex) { throw ex; } } private void butpath_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK ) { textBox1.Text = folderBrowserDialog1.SelectedPath; } } private void butsave_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { txtsavepath.Text = folderBrowserDialog1.SelectedPath; } } private void button2_Click(object sender, EventArgs e) { if (fontDialog1.ShowDialog() == DialogResult.OK) { txtfont.Text = fontDialog1.Font.Name.ToString()+","+ fontDialog1.Font.Size.ToString(); } } private void button3_Click(object sender, EventArgs e) { this.Close(); } } }
此动态链接库是专门用于美化程序的菜单的。实现方法是在原有菜单的基础上直接调用,非常方便。库经过长时间的修改,已经很完善了。现在将其发布出来,供大家使用。 【发行文件】 DLL文件:cutemenu.dll LIB文件:cutemenu.lib VC++头文件:cutemenu.h VB声明模块:cutemenu.bas PB包含文件:cutemenu.pbi 帮助文件:help.chm 【特点】 1、内部实现完全依赖已经建立好的菜单,没有另行建立任何结构数组用来保存自绘菜单信息。 2、用户可以自己设置自绘风格(30多项)。支持渐变填充、Alpha混合、32位透明位图菜单项,界面美观。 3、使用方便,仅在适当的时候调用3个函数即可。 4、库文件体积小巧。 【编译器】 PureBasic 4.20 【使用说明】 文件夹“Demo Code”中有 Visual C++ 6.0、Visual Basic 6.0、PureBasic 三种 IDE 环境下的演示代码,用户可根据具体情况选择参考。 使用的具体思路是对已存在的菜单调用 AssignOwnerDraw(HMENU hMenu, UINT fSubIncluded) 函数,该函数会为该菜单的每项设置 MFT_OWNERDRAW 标志。如果 fSubIncluded 不为0,函数会遍历该菜单下挂的所有菜单的各菜单项。这个函数可以在加载菜单后就调用,也可以在 WM_INITMENU/WM_INITMENUPOPUP 消息中即时调用。之后,在消息循环中的 WM_MEASUREITEM 和 WM_DRAWITEM 消息分别调用 MeasureItem(LPMEASUREITEMSTRUCT lpmis) 和 DrawItem(LPDRAWITEMSTRUCT lpdis) 实现自绘。 链接库刚运行时的菜单风格是当前系统默认的,用户可以凭借库里提供的另两个功能强大的函数 GetMenuStyle(LPMENUSTYLE lpms) 和 SetMenuStyle(LPMENUSTYLE lpms) 实现项目颇为丰富(30多项)的菜单风格设置。恰当地设置各参数,可以逼真地模仿别的软件的菜单风格,也可以随心所欲地实现自己独特的风格。 各函数的调用和其它一些技术问题请参阅目录下的帮助文档。

1,075

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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