写了两个简单的小工具,文件夹文件操作的

一,文件夹A下的文件夹下的文件,移到文件夹A下。

二,经常上贴吧什么的,有些图贴,会直接网页全部保存为,结果是一个html文件,和引用资源的文件夹,文件夹下有很多无用的文件,写了个方法,把图片另存为,其余都删掉。

代码。

namespace 文件夹内容放到上级
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){folderBrowserDialog1.ShowDialog();this.textBox1.Text = folderBrowserDialog1.SelectedPath;}private void button2_Click(object sender, EventArgs e){//得到所有的目录var a = Directory.GetDirectories(this.textBox1.Text);for (int i = 0; i < a.Length; i++){//得到目录下的文件var b = Directory.GetFiles(a[i]);//移动文件到父级for (int j = 0; j < b.Length; j++){string filename = GetFileName(b[j].ToString());System.IO.File.Move(b[j], this.textBox1.Text + "\\" + filename);}//删除该目录Directory.Delete(a[i], true);}}private void button3_Click(object sender, EventArgs e){//得到所有的文件var a = Directory.GetFiles(this.textBox1.Text, "*.htm");for (int i = 0; i < a.Length; i++){int legth = a[i].Length;//文件夹的名称。int extlength=4;if (a[i].IndexOf("html") > -1) {extlength = 5;}string dpath = a[i].Substring(0, legth - extlength)+"_files";//得到文件夹下的所有图片
ArrayList allimg = new ArrayList();var jpgs = Directory.GetFiles(dpath, "*.jpg");for (int jpg = 0; jpg < jpgs.Length; jpg++){long size = new FileInfo(jpgs[jpg]).Length;if (size > 10 * 1024){allimg.Add(jpgs[jpg]);}}var gifs = Directory.GetFiles(dpath, "*.gif");for (int gif = 0; gif < gifs.Length; gif++){long size = new FileInfo(gifs[gif]).Length;if (size > 80 * 1024){allimg.Add(gifs[gif]);}}var bmps = Directory.GetFiles(dpath, "*.bmp");for (int bmp = 0; bmp < bmps.Length; bmp++){long size = new FileInfo(bmps[bmp]).Length;if (size > 50 * 1024){allimg.Add(bmps[bmp]);}}//创建文件夹string newdpaht = a[i].Substring(0, legth - extlength);CreateFolder(newdpaht);//把图片放到这个文件夹里。foreach (var c in allimg){string filename = GetFileName(c.ToString());File.Move(c.ToString(), newdpaht + "\\"+filename);}// 删除原HTML和文件夹
                File.Delete(a[i]);Directory.Delete(dpath,true);}}/// <summary>/// 创建目录路径/// </summary>/// <param name="folderPath">物理路径</param>public static void CreateFolder(string folderPath){if (!System.IO.Directory.Exists(folderPath))System.IO.Directory.CreateDirectory(folderPath);}public static string GetFileName( string filePath){return filePath.Substring(filePath.LastIndexOf("\\") + 1, filePath.Length - filePath.LastIndexOf("\\") - 1);}}
}

 

转载于:https://www.cnblogs.com/zihunqingxin/p/3200454.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/274154.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

前置声明相关

前置声明相关 一个前置声明是指在程序员尚未给出完整定义之前对一个标示符(一个类型、一个变量或者一个函数)的声明。一个很简单的例子就是我们在函数A中使用了函数B&#xff0c;但是函数B的声明在函数A之后&#xff0c;这个时候&#xff0c;就需要对函数B进行前置声明&#xf…

陌生人社会_陌生人之旅

陌生人社会The Last of Us Part II is a game that is deeply invested in the minutiae of its characters. The pain they cause, the things that drive them, and the particularities of their self-destruction and salvation. The game’s commitment to the true natur…

设计师更高效_要成为更好的设计师,我们需要更多的时间进行游戏

设计师更高效重点 (Top highlight)I’m a busy designer. I’m fortunate to be booked out months in advance. My freelance career has proven more stable than other’s “jobs”. I don’t wear busy as a badge of honour. I don’t condone hustle culture or compare …

java数据类型及其说明

Java数据类型及其说明java基本数据类型&#xff1a; java数据类型分为基本数据类型和引用数据类型&#xff0c;基本数据类型就是4类8种&#xff0c;分为数值类型&#xff08;整数型[byte&#xff0c;short&#xff0c;int&#xff0c;long]&#xff09;&#xff0c;字符型&…

ux设计师薪水_公司与 设计机构:UX设计师的津贴和陷阱

ux设计师薪水Written by Yegor Tsynkevich由Yegor Tsynkevich撰写 The more companies understand the power of a great user experience design and its impact on customer loyalty, the more they are willing to have it embedded in their culture. With so much emphas…

ZOJ 2165 Red and Black

1.采用dfs&#xff1a; #include <iostream>#include <cstdio>#include <cstring>#include <string>using namespace std;char map[25][25];int count 1;int r,c;int dx[4] {1,-1,0,0};int dy[4] {0,0,1,-1};bool judge(int x,int y){ if(x<0…

java中的equals用法

在Object 类中定义有&#xff1a; 1、public boolean equals(Object object )方法提供定义对象是否“相等”逻辑。 2、Object的equals方法定义为&#xff1a;x.equals(y)当x和y是同一个对象的引用时&#xff0c;返回true&#xff0c;否则返回false 3、在其他一些类中&#xff0…

根据图片获得配色方案_配色系列(1)—从图片中获得配色灵感

根据图片获得配色方案前言 (Foreword) When we start designing mobile web pages, we always need to determine the color scheme of the web page first. Well, at this time, unless the customer proposes a color scheme, most of the situations we have to face is to …

七大查找算法

1. 顺序查找2. 二分查找3. 插值查找4. 斐波那契查找5. 树表查找6. 分块查找7. 哈希查找 查找是在大量的信息中寻找一个特定的信息元素&#xff0c;在计算机应用中&#xff0c;查找是常用的基本运算&#xff0c;例如编译程序中符号表的查找。本文简单概括性的介绍了常见的七种查…

HA2795Billboard 可用线段树

#include<iostream>using namespace std;#include<cstdio>#include<algorithm>#define maxn 200005int h,n,w;int root[maxn<<4];int ans;//标记void make_tree(int l,int r,int rt){if(lr){root[rt]w;return ;}int mid(rl)/2;make_tree(l,mid,rt*2);m…

axure下拉列表框单选框_如何在Axure中创建下拉菜单和组合框

axure下拉列表框单选框First, let’s clarify what exactly is a dropdown menu, and what is a combo box, aren’t they the same? Well … no, not really, let me explain.首先&#xff0c;让我们弄清楚什么是下拉菜单&#xff0c;什么是组合框&#xff0c;不是吗&#xf…

Android 第一课 Activity

以下说明基于Android Studio&#xff0c;简称AS。&#xff08;红色字体为自行添加&#xff0c;注在醒目&#xff09; 具体包括&#xff1a;创建活动创建项目 加载布局 在AndroidManifest文件中注册 活动中使用&#xff08;提醒&#xff09;Toast 在活动使用&#xff08;菜…

figma设计_一种在Figma中跟踪设计迭代的简单方法

figma设计As designers, telling a good story is always part of the job. A great story engages the client with the journey of decision making; it shows your team the breadth and depth of the exploration; it also encourages us to reflect on our own design pro…

Android 第二课 Intent

上一节&#xff0c;掌握了活动的创建&#xff0c;但是在启动器中点击应用的图标只会进入到该应用的主活动&#xff0c;那么&#xff0c;如何从主活动跳转到其他活动呢&#xff1f;显式IntentIntent有多个构造函数&#xff0c;其中一个是Intent(Context packContext,Class<?…

ok~加油!

你有梦想&#xff0c;放手去做&#xff01;转载于:https://www.cnblogs.com/the-one/p/3217124.html

latex 插图 上下放_专辑插图中上下文中的文本

latex 插图 上下放Especially if, like me, you’re not properly educated in the world of visual design, typography, and all those other things that a formal education can bring. We’re kind of playing around until something fits right, and doesn’t feel jarr…

亡羊补牢,为时不晚?

亡羊补牢&#xff0c;为时不晚 人总是想着第二次比第一次做的好&#xff0c;可是会一直有第二次机会吗&#xff1f;当你思考好&#xff0c;决定做一件事情的时候&#xff0c;为什么不坚持下去呢&#xff1f;当你思考好&#xff0c;记住坚持到底就会胜利。祝福自己&#xff0…

2013年7月份第4周51Aspx源码发布详情

大型企业通用管理ERP源码 2013-7-26 [VS2010]2013.7.4更新内容&#xff1a;1.修复决策模式-客户等级不能保存问题。2.修复企业知识库有报错问题。3.修复运营模式-人力资源分析模块-在部分模块点击查询后&#xff0c;水晶报表显示无法加载文件问题&#xff0c;4.修复行政办公模…

视觉感知_产品设计中的视觉感知

视觉感知The role of the UX designer has evolved immensely over time, but at its core, it remains the same- UX设计人员的角色随着时间的流逝而发生了巨大的变化&#xff0c;但从本质上讲&#xff0c;它保持不变- to deliver information to users in an effective mann…

Android 第三课 Activity的生命周期

新建项目ActivityLifeCycleTest&#xff0c;创建主活动后&#xff0c;再新建两个子活动--NormalActivity和DialogActivity。 现在活动及其对应布局文件创建完毕。 编辑normal_layout.xml文件&#xff0c;代码如下&#xff1a; <?xml version"1.0" encoding"…