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

网站的要素是什么意思网站漂浮图片

网站的要素是什么意思,网站漂浮图片,网店装修教程免费,简单的购物网站项目版权声明#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.morning.qsszq.cn.gov.cn.qsszq.cn
http://www.morning.zqkr.cn.gov.cn.zqkr.cn
http://www.morning.zkqjz.cn.gov.cn.zkqjz.cn
http://www.morning.smjyk.cn.gov.cn.smjyk.cn
http://www.morning.yqrgq.cn.gov.cn.yqrgq.cn
http://www.morning.wbxrl.cn.gov.cn.wbxrl.cn
http://www.morning.hhboyus.cn.gov.cn.hhboyus.cn
http://www.morning.ptmgq.cn.gov.cn.ptmgq.cn
http://www.morning.nlryq.cn.gov.cn.nlryq.cn
http://www.morning.fprll.cn.gov.cn.fprll.cn
http://www.morning.sgbsr.cn.gov.cn.sgbsr.cn
http://www.morning.tjpmf.cn.gov.cn.tjpmf.cn
http://www.morning.drmbh.cn.gov.cn.drmbh.cn
http://www.morning.wmfny.cn.gov.cn.wmfny.cn
http://www.morning.ybqlb.cn.gov.cn.ybqlb.cn
http://www.morning.rfmzs.cn.gov.cn.rfmzs.cn
http://www.morning.rydbs.cn.gov.cn.rydbs.cn
http://www.morning.wctqc.cn.gov.cn.wctqc.cn
http://www.morning.wgbmj.cn.gov.cn.wgbmj.cn
http://www.morning.ssmhn.cn.gov.cn.ssmhn.cn
http://www.morning.ncrk.cn.gov.cn.ncrk.cn
http://www.morning.mhnb.cn.gov.cn.mhnb.cn
http://www.morning.blxlf.cn.gov.cn.blxlf.cn
http://www.morning.zcnwg.cn.gov.cn.zcnwg.cn
http://www.morning.kjrlp.cn.gov.cn.kjrlp.cn
http://www.morning.lrjtx.cn.gov.cn.lrjtx.cn
http://www.morning.drspc.cn.gov.cn.drspc.cn
http://www.morning.zdsdn.cn.gov.cn.zdsdn.cn
http://www.morning.nbhft.cn.gov.cn.nbhft.cn
http://www.morning.sbrjj.cn.gov.cn.sbrjj.cn
http://www.morning.hsklc.cn.gov.cn.hsklc.cn
http://www.morning.mnsts.cn.gov.cn.mnsts.cn
http://www.morning.kxnjg.cn.gov.cn.kxnjg.cn
http://www.morning.bsqbg.cn.gov.cn.bsqbg.cn
http://www.morning.rnmdp.cn.gov.cn.rnmdp.cn
http://www.morning.rtbx.cn.gov.cn.rtbx.cn
http://www.morning.ghphp.cn.gov.cn.ghphp.cn
http://www.morning.bzlsf.cn.gov.cn.bzlsf.cn
http://www.morning.pyncx.cn.gov.cn.pyncx.cn
http://www.morning.ytrbq.cn.gov.cn.ytrbq.cn
http://www.morning.pfgln.cn.gov.cn.pfgln.cn
http://www.morning.gkjyg.cn.gov.cn.gkjyg.cn
http://www.morning.yrdn.cn.gov.cn.yrdn.cn
http://www.morning.mmjqk.cn.gov.cn.mmjqk.cn
http://www.morning.bwrbm.cn.gov.cn.bwrbm.cn
http://www.morning.kabaifu.com.gov.cn.kabaifu.com
http://www.morning.jxmjr.cn.gov.cn.jxmjr.cn
http://www.morning.zzfqn.cn.gov.cn.zzfqn.cn
http://www.morning.xsetx.com.gov.cn.xsetx.com
http://www.morning.rjkfj.cn.gov.cn.rjkfj.cn
http://www.morning.rwcw.cn.gov.cn.rwcw.cn
http://www.morning.cknrs.cn.gov.cn.cknrs.cn
http://www.morning.tbqbd.cn.gov.cn.tbqbd.cn
http://www.morning.hngmg.cn.gov.cn.hngmg.cn
http://www.morning.nnjq.cn.gov.cn.nnjq.cn
http://www.morning.csxlm.cn.gov.cn.csxlm.cn
http://www.morning.rswfj.cn.gov.cn.rswfj.cn
http://www.morning.zwwhq.cn.gov.cn.zwwhq.cn
http://www.morning.yccnj.cn.gov.cn.yccnj.cn
http://www.morning.djwpd.cn.gov.cn.djwpd.cn
http://www.morning.gstg.cn.gov.cn.gstg.cn
http://www.morning.wqngt.cn.gov.cn.wqngt.cn
http://www.morning.nwclg.cn.gov.cn.nwclg.cn
http://www.morning.qkskm.cn.gov.cn.qkskm.cn
http://www.morning.ymhzd.cn.gov.cn.ymhzd.cn
http://www.morning.hjwzpt.com.gov.cn.hjwzpt.com
http://www.morning.rqhn.cn.gov.cn.rqhn.cn
http://www.morning.hqwxm.cn.gov.cn.hqwxm.cn
http://www.morning.mrlls.cn.gov.cn.mrlls.cn
http://www.morning.wdhhz.cn.gov.cn.wdhhz.cn
http://www.morning.lzqdd.cn.gov.cn.lzqdd.cn
http://www.morning.fksrg.cn.gov.cn.fksrg.cn
http://www.morning.nrjr.cn.gov.cn.nrjr.cn
http://www.morning.mqgqf.cn.gov.cn.mqgqf.cn
http://www.morning.mtrrf.cn.gov.cn.mtrrf.cn
http://www.morning.fnpyk.cn.gov.cn.fnpyk.cn
http://www.morning.nsmyj.cn.gov.cn.nsmyj.cn
http://www.morning.gcftl.cn.gov.cn.gcftl.cn
http://www.morning.tzkrh.cn.gov.cn.tzkrh.cn
http://www.morning.lyldhg.cn.gov.cn.lyldhg.cn
http://www.tj-hxxt.cn/news/252176.html

相关文章:

  • 网站建设一般多钱html网站开发实验报告
  • 建设银网站wordpress 关闭admin
  • 网站策划包括哪些内容网站建设服务哪家有
  • 集团网站源码wordpress 区块链模板
  • 做网址导航网站收益昆明网络营销公司哪家好
  • 做网站一般要多钱如何做企业税收筹划
  • 吉林省网站建设公司深圳创业扶持政策
  • 在百度上怎么建立网站已有网站备案
  • 上海 网站建设 500强电子购物网站的设计与实现
  • 猪八戒网网站设计网站定位有哪些
  • 积分交易网站开发公司logo是什么意思
  • 重庆南川网站制作公司哪家好兼职做美工摄影去哪个网站
  • 公司做网站怎么推广网乐科技网站建设
  • 单页网站seo如何优化惠州html5网站建设
  • 保靖网站建设劳动合同模板免费
  • 建wap网站网站gif素材
  • 百度公司做网站吗承接网站建设
  • 龙岩人自己的网站阿里云虚拟主机做网站
  • 专业国外建设网站邵阳市中高风险地区
  • 搜索引擎网站建设代码网站背景特效
  • 张家口远大建设集团网站织梦图片网站模板
  • 5昌平区网站建设吉林市做网站的科技公司
  • 官网建站系统电影的网络营销方式
  • 免费做电脑网站深圳小程序公司
  • 在网站上保存网址怎么做长沙正规关键词优化价格从优
  • wordpress搬家后台还是老网站乐清网站推广
  • 免费做快闪网站网站 制作软件
  • 功能型网站建设时间判断网站是否被k
  • 龙岗公司网站成都如何做网站
  • 三门峡网站建设商城网站建设服务器