当前位置: 首页 > news >正文

网站的要素是什么意思wordpress 图片排列

网站的要素是什么意思,wordpress 图片排列,wordpress 自定义登录,企业网站源码 多语言版权声明#xff1a;本文为博主原创文章#xff0c;转载请在显著位置标明本文出处以及作者网名#xff0c;未经作者允许不得用于商业目的。 10.2.1 DirectoryInfo类 DirectoryInfo类可以获得目录信息。 DirectoryInfo常用属性#xff1a; Name#xff1a;获取Director…版权声明本文为博主原创文章转载请在显著位置标明本文出处以及作者网名未经作者允许不得用于商业目的。 10.2.1 DirectoryInfo类 DirectoryInfo类可以获得目录信息。 DirectoryInfo常用属性 Name获取DirectoryInfo实例的名称例如c:\windows\system32将返回system32。FullName获取目录或文件的完整目录。例如c:\windows\system32将返回c:\windows\system32。Attributes目录的属性。Exists目录是否存在。CreationTime目录的创建时间。LastWriteTime目录的最后修改时间。Parent目录的父目录。 DirectoryInfo常用方法 Create创建目录。Delete删除目录使用此方法带参数的重载可以实现删除目录下的子目录和文件否则只能删除空目录。MoveTo移动目录。注意此方法只能在同一个磁盘分区下移动。GetDirectories返回当前目录的子目录列表这是一个DirectoryInfo数组。 GetFiles返回当前目录的文件列表这是一个FileInfo数组。关于FileInfo类请参看第10.3.1节。 10.2.1.1 获取目录信息 【例 10.2】【项目code10-002】获得计算机上某个目录的信息。 当选择某个文件夹后立即在文本框中显示该文件夹的相关信息 private void button1_Click(object sender, EventArgs e) { FolderBrowserDialog fbd new FolderBrowserDialog(); fbd.ShowNewFolderButton false; if (fbd.ShowDialog() ! DialogResult.OK) return; string folderpath fbd.SelectedPath; DirectoryInfo di new DirectoryInfo(folderpath); textBox1.Text 文件夹 di.Name \r\n; textBox1.Text 路径 di.FullName \r\n; textBox1.Text 创建日期 di.CreationTime.ToString(yyyy-MM-dd) \r\n; textBox1.Text 最后修改日期 di.LastWriteTime.ToString(yyyy-MM-dd) \r\n; textBox1.Text 属性 getFolderAttr(di.Attributes) \r\n; } //获得文件夹属性 private string getFolderAttr(FileAttributes attr) { string strAttr ; if((attr FileAttributes.Archive)FileAttributes.Archive) strAttr 备份; if ((attr FileAttributes.Hidden) FileAttributes.Hidden) strAttr 隐藏; if ((attr FileAttributes.Compressed) FileAttributes.Compressed) strAttr 压缩; if ((attr FileAttributes.Directory) FileAttributes.Directory) strAttr 目录; if ((attr FileAttributes.Encrypted) FileAttributes.Encrypted) strAttr 加密; if ((attr FileAttributes.Offline) FileAttributes.Offline) strAttr 脱机; if ((attr FileAttributes.ReadOnly) FileAttributes.ReadOnly) strAttr 只读; if ((attr FileAttributes.System) FileAttributes.System) strAttr 系统; if ((attr FileAttributes.Temporary) FileAttributes.Temporary) strAttr 临时; return strAttr; } 运行结果如下图所示 图10-2 获取目录信息 10.2.1.2 获取子目录和文件 获取当前目录的子目录和所有文件主要是使用GetDirectories和GetFiles方法这两个方法返回包含的子目录DirectoryInfo数组和文件FileInfo数组只需要分别遍历这两个数组即可获得相关信息。 【例 10.3】【项目code10-003】获得子目录和文件。 private void button1_Click(object sender, EventArgs e) { FolderBrowserDialog fbd new FolderBrowserDialog(); if (fbd.ShowDialog() ! DialogResult.OK) return; label1.Text fbd.SelectedPath; DirectoryInfo di new DirectoryInfo(label1.Text); listBox1.Items.Clear(); //遍历当前目录下的子目录 foreach (DirectoryInfo subdi in di.GetDirectories()) { listBox1.Items.Add(目录 subdi.Name); } //遍历当前目录下的文件 foreach (FileInfo fi in di.GetFiles()) { listBox1.Items.Add(文件 fi.Name); } } 运行结果如下图所示 图10-3 获得选定目录的子目录和文件 10.2.1.3 设置目录属性 通过DirectoryInfo类的Attributes属性可以获得和设置目录属性。Attributes的值是一个FileAttributes枚举它提供了文件和目录的属性。 表10-1 FileAttributes枚举常用成员及对应属性说明 成员名称 对应属性说明 成员名称 对应属性说明 Archive 备份 Normal 正常 Compressed 压缩 Offline 脱机 Directory 指示这是目录 ReadOnly 只读 Encrypted 加密 System 系统 Hidden 隐藏 Temporary 临时 判断现有属性是否包括某个属性请使用现有属性 And 某个属性 表10-2 判断是否包含只读属性 属性 十进制值 操作 二进制值 十六进制值 NR 129 And 1 0 0 0 0 0 0 1 81 ReadOnly 1 0 0 0 0 0 0 0 1 1 ReadOnly 1 0 0 0 0 0 0 0 1 1 现有属性基础上增加某个属性请使用现有属性 Or 某个属性 表10-3 增加隐藏属性 属性 十进制值 操作 二进制值 十六进制值 Normal 128 | Or 1 0 0 0 0 0 0 0 80 Hidden 2 0 0 0 0 0 0 1 0 2 NH 130 1 0 0 0 0 0 1 0 82 从现有属性中排除某个属性请使用现有属性 Xor 某个属性 表10-4 排除只读属性 属性 十进制值 操作 二进制值 十六进制值 NR 129 ^ Xor 1 0 0 0 0 0 0 1 81 ReadOnly 1 0 0 0 0 0 0 0 1 1 Normal 128 1 0 0 0 0 0 0 0 80 注意微软提供的很多Api常量和.Net常量都类似于FileAttributes常量枚举即按照 0、1、2、4、8……这样定义的很方便使用、|、^等位运算符。 【例 10.4】【项目code10-004】设置目录属性。 //选择目录并获得其属性 private void button1_Click(object sender, EventArgs e) { FolderBrowserDialog fbd new FolderBrowserDialog(); if (fbd.ShowDialog() ! DialogResult.OK) return; label1.Text fbd.SelectedPath; DirectoryInfo di new DirectoryInfo(label1.Text); //目录有只读属性,那么勾选CheckBox1 if ((di.Attributes FileAttributes.ReadOnly) FileAttributes.ReadOnly ) checkBox1.Checked true; //目录有隐藏属性,那么勾选CheckBox2 if ((di.Attributes FileAttributes.Hidden) FileAttributes.Hidden) checkBox2.Checked true; //目录有系统属性,那么勾选CheckBox3 if ((di.Attributes FileAttributes.System) FileAttributes.System) checkBox3.Checked true; } //设置指定目录的属性 private void button2_Click(object sender, EventArgs e) { DirectoryInfo di new DirectoryInfo(label1.Text); if (di.Exists false) return; FileAttributes fa di.Attributes; if ((fa FileAttributes.ReadOnly) FileAttributes.ReadOnly) { //如果有只读属性而设置取消只读那么使用异或方式 if (checkBox1.Checked false) fa fa ^ FileAttributes.ReadOnly; } else { //如果没有只读属性而设置只读那么使用或方式 if (checkBox1.Checked true) fa fa | FileAttributes.ReadOnly; } if ((fa FileAttributes.Hidden) FileAttributes.Hidden) { //如果有隐藏属性而设置取消隐藏那么使用异或方式 if (checkBox2.Checked false) fa fa ^ FileAttributes.Hidden; } else { //如果没有隐藏属性而设置隐藏那么使用或方式 if (checkBox2.Checked true) fa fa | FileAttributes.Hidden; } if ((fa FileAttributes.System) FileAttributes.System) { //如果有系统属性而设置取消系统那么使用异或方式 if (checkBox3.Checked false) fa fa ^ FileAttributes.System; } else { //如果没有系统属性而设置系统那么使用或方式 if (checkBox3.Checked true) fa fa | FileAttributes.System; } //目录设置新属性 di.Attributes fa; } 运行结果如下图所示 图10-4 设置目录属性并使用attrib命令验证 10.2.1.4 目录的创建、删除和移动 目录的创建、删除和移动分别使用到了DirectoryInfo类的Create、Delete和MoveTo方法。 【例 10.5】【项目code10-005】目录的创建、删除和移动。 //获得源目录路径 private void button1_Click(object sender, EventArgs e) { FolderBrowserDialog fbd new FolderBrowserDialog(); if (fbd.ShowDialog() ! DialogResult.OK) return; label1.Text fbd.SelectedPath; } //获得目标目录路径 private void button2_Click(object sender, EventArgs e) { FolderBrowserDialog fbd new FolderBrowserDialog(); if (fbd.ShowDialog() ! DialogResult.OK) return; label2.Text fbd.SelectedPath; } //在源目录下创建一个子目录 csharp private void button3_Click(object sender, EventArgs e) { if (label1.Text ) return; string newFolder label1.Text.Substring(label1.Text.Length - 1, 1) \\ ? label1.Text.Substring(0, label1.Text.Length - 1) : label1.Text; DirectoryInfo di new DirectoryInfo(newFolder \\csharp); if(di.Exists ) { MessageBox.Show(目录已经存在,不能创建该目录。, 错误信息); return; } di.Create(); MessageBox.Show(目录创建成功。, 提示信息); } //删除源目录 private void button4_Click(object sender, EventArgs e) { if (label1.Text ) return; DirectoryInfo di new DirectoryInfo(label1.Text ); if (di.Parent null) { MessageBox.Show(为确保文件安全不允许删除根目录, 错误信息); return; } if(di.Exists ) { try { if (MessageBox.Show(确实要删除此目录, 警告信息, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) DialogResult.Cancel) return; di.Delete(true); MessageBox.Show(目录已经成功删除。, 提示信息); } catch(Exception ex) { MessageBox.Show(删除目录时发生错误 ex.Message, 错误信息); } } else { MessageBox.Show(目录不存在。, 错误信息); } } //移动源目录到目标目录注意必须在同一分区下移动 private void button5_Click(object sender, EventArgs e) { if (label1.Text | label2.Text ) return; DirectoryInfo di new DirectoryInfo(label1.Text); string toFolder; toFolder label2.Text.Substring(label2.Text.Length - 1, 1) \\ ? label2.Text : label2.Text \\; toFolder toFolder di.Name; if(di.Exists) { try { di.MoveTo(toFolder); MessageBox.Show(目录移动完成。, 提示信息); } catch(Exception ex) { MessageBox.Show(移动目录时发生错误 ex.Message, 错误信息); } } else { MessageBox.Show(目录不存在。, 错误信息); } } 运行结果如下图所示 图10-5目录的创建、删除和移动 10.2.2 Directory类 除了DirictoryInfo类外VB.Net还提供了Directory类来操作目录、获得目录信息。 Directory类与DirectoryInfo类相比Directory没有属性提供的方法都是静态方法可以直接使用而DirectoryInfo的方法需要类实例化后使用。 其实DirectoryInfo的一些方法甚至就是调用Directory对应的方法。 Directory常用方法 CreateDirectory创建目录。Delete删除目录。Move移动目录。GetLogicalDrives检索此计算机上格式为“驱动器号:\”的逻辑驱动器的名称这是一个字符串数组。GetDirectories子目录的名称包括其路径这是一个字符串数组。GetFiles目录中文件的名称包括其路径这是一个字符串数组。GetCreationTime获得目录创建时间。GetLastWriteTime获得目录最后修改时间。GetLastAccessTime获得目录最后访问时间。GetParent获得父目录这是一个DirectoryInfo类型。SetCreationTime设置目录创建时间。SetLastWriteTime设置目录最后修改时间。SetLastAccessTime设置目录最后访问时间。GetCurrentDirecotry获得程序所在路径。Exists目录是否存在。 10.2.2.1 获取目录信息 【例 10.6】【项目code10-006】获取某个目录的信息。 private void button1_Click(object sender, EventArgs e) { FolderBrowserDialog fbd new FolderBrowserDialog(); fbd.ShowNewFolderButton false; if (fbd.ShowDialog() !DialogResult.OK) return; string folderPath fbd.SelectedPath; textBox1.Text 路径 folderPath \r\n; textBox1.Text 根目录 Directory.GetDirectoryRoot(folderPath) \r\n; if (Directory.GetParent(folderPath)!null) textBox1.Text 父目录 Directory.GetParent(folderPath).FullName \r\n;            textBox1.Text 创建日期 Directory.GetCreationTime(folderPath).ToString(yyyy-MM-dd) \r\n; textBox1.Text 最后修改日期 Directory.GetLastWriteTime(folderPath).ToString(yyyy-MM-dd) \r\n; textBox1.Text 最后访问日期 Directory.GetLastAccessTime(folderPath).ToString(yyyy-MM-dd); } 运行结果如下图所示 图10-6 获取目录信息 10.2.2.2 获取子目录和文件 获取当前目录的子目录和所有文件主要是使用GetDirectories和GetFiles方法这两个方法不同于DirectoryInfo类提供的方法它们返回的是包含的子目录和文件的全路径的字符串数组。 【例 10.7】【项目code10-007】获得子目录和文件。 private void button1_Click(object sender, EventArgs e) { FolderBrowserDialog fbd new FolderBrowserDialog(); if (fbd.ShowDialog() ! DialogResult.OK) return; listBox1.Items.Clear(); string selPath fbd.SelectedPath; //遍历所有的子目录 foreach ( string subdirectory in Directory.GetDirectories(selPath)) { listBox1.Items.Add(目录 subdirectory); } //遍历所有的文件 foreach (string file in Directory.GetFiles(selPath)) { listBox1.Items.Add(文件 file); } } 运行结果同【例 10.3】。 10.2.2.3 目录的创建、删除和移动 目录的创建、删除和移动分别使用到了Directory类的CreateDirectory、Delete和Move方法。 【例 10.8】【项目code10-008】目录的创建、删除和移动。 //获得源目录路径 private void button1_Click(object sender, EventArgs e) { FolderBrowserDialog fbd new FolderBrowserDialog(); if (fbd.ShowDialog() ! DialogResult.OK) return; label1.Text fbd.SelectedPath; } //获得目标目录路径 private void button2_Click(object sender, EventArgs e) { FolderBrowserDialog fbd new FolderBrowserDialog(); if (fbd.ShowDialog() ! DialogResult.OK) return; label2.Text fbd.SelectedPath; } //在源目录下创建一个子目录 csharp private void button3_Click(object sender, EventArgs e) { string newFolder label1.Text.Substring(label1.Text.Length - 1, 1) \\ ? label1.Text.Substring(0, label1.Text.Length - 1) : label1.Text; newFolder \\csharp; if (Directory.Exists(newFolder)) { MessageBox.Show(目录已经存在,不能创建该目录。, 错误信息); return; } Directory.CreateDirectory(newFolder); MessageBox.Show(目录创建成功。, 提示信息); } //删除源目录 private void button4_Click(object sender, EventArgs e) { if (label1.Text ) return; string folder label1.Text; if (Directory.GetParent(folder) null) MessageBox.Show(为确保文件安全不允许删除根目录, 错误信息); return; if(Directory.Exists (folder)) { try { if (MessageBox.Show(确实要删除此目录, 警告信息, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) DialogResult.Cancel) return; //调用Delete方法删除参数True表示要删除该目录中的子目录和文件 Directory.Delete(folder, true); //如果使用不带参数的方法只能是删除空目录 Directory.Delete(folder); MessageBox.Show(目录已经成功删除。, 提示信息); } catch(Exception ex) { MessageBox.Show(删除目录时发生错误 ex.Message, 错误信息); } } else { MessageBox.Show(目录不存在。, 错误信息); } } //移动源目录到目标目录 //注意必须在同一分区下移动 private void button5_Click(object sender, EventArgs e) { if (label1.Text | label2.Text ) return; DirectoryInfo di new DirectoryInfo(label1.Text); string toFolder label2.Text.Substring(label2.Text.Length - 1, 1) \\ ? label2.Text : label2.Text \\; toFolder di.Name; if(Directory.Exists(label1.Text)) { try { //调用MoveTo方法移动 Directory.Move(label1.Text, toFolder); MessageBox.Show(目录移动完成。, 提示信息); } catch (Exception ex) { MessageBox.Show(移动目录时发生错误 ex.Message, 错误信息); } } else { MessageBox.Show(目录不存在。, 错误信息); } } 运行结果同【例 10.5】。 学习更多vb.net知识请参看vb.net 教程 目录 学习更多C#知识请参看C#教程 目录
http://www.ho-use.cn/article/10816511.html

相关文章:

  • 贵阳网站方舟网络最好网站开发有哪些服务器
  • 上传了网站标志怎么弄360建筑网上怎么删除投递信息
  • o2o网站系统建设重庆企业的网站建设
  • 合肥专业做网站公司有哪些中国建设银行济南招聘信息网站
  • 赣州 做网站免费行情软件的特点和优势
  • 网站设计规划范文医疗器械有限公司
  • 电子商务网站建设论文课题国外电商网站如何做icp备案
  • 网站域名解析错误怎么办自己做的网站网页滑动不
  • 建站网址导航hao123wordpress里的模板怎么用
  • 做详情页到那个网站找模特素材网站首页浮动广告怎么做
  • 宿州网站建设网站制作网站软件哪个好
  • 网站怎么搬家wordpress数据库表管理
  • 青海营销网站建设公司婚庆公司网站建设策划书
  • 企业门户网站建设报告推广网站广告有哪些
  • 贵州省城乡建设部官方网站google seo 营销网站
  • 产品公司网站建设方案模板建设银行企业网站首页
  • 山西省财政厅网站三基建设专栏广东深圳龙岗区邮政编码
  • 网站开发前期工作苏州企业网站seo
  • 怎么加快登录网站速度公司网站还有用吗
  • 用dw做网站怎么添加背景图片网站建设优化学习
  • 国土资源局加强网站建设什么软件做美食视频网站好
  • 泰安招聘网站有哪些网站如何做原创
  • 外贸网站搜索 引擎优化方法网站建设与规划实验心得
  • 安徽建设网站公司如何利用互联网宣传与推广
  • 销售产品单页面网站模板深圳勘察设计网
  • 网站建设项目创业计划书团员个人信息查询官网
  • wordpress新建网站后台无法登陆建设网站e护航下载
  • 请简述企业网站的推广阶段及其特点水果商城网站制作多少钱
  • 到哪里建网站石家庄网络开发公司
  • 毕业设计团购网站建设泰安贴吧百度贴吧