DOS BAT关闭文件夹
DOS 关闭文件夹
package com.cczhang.jsabms;import com.cczhang.utils.EncodingUtil;
import com.csvreader.CsvReader;import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;public class CheckBackFiles {//static String WindowsTitle = "";static Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();static String filePath = "C:\\Users\\zhangcongcong\\Desktop\\1.csv"; //源文件路径static String overPath = "C:\\Users\\zhangcongcong\\Desktop\\test.csv"; //最后生成的csv文件路径static String screenPath = "C:\\soft\\screen\\"; //截屏路径public static void main(String[] args) throws IOException, InterruptedException, AWTException {System.out.println("Java -jar CheckBackFiles.jar 源文件路径 最后生成的csv文件路径 截屏路径");if(args.length > 2){filePath = args[0];overPath = args[1];screenPath = args[2];}Robot robot = new Robot();File file = new File(filePath);File batdir = new File(file.getParent() +File.separatorChar+ "bat");batdir.mkdirs();List<String[]> allPath = resolveFile(file);for(int i = 1 ; i < allPath.size() ; i ++){String[] filePath = allPath.get(i);String[] newPathInfo = Arrays.copyOf(filePath,filePath.length +4); //保存截图for(int m = 3 ; m < filePath.length - 2 ; m ++){Runtime runtime = Runtime.getRuntime();if(!"".equals(filePath[m])){//判断当前路径是否存在//如果存在 执行DOS打开当前命令窗口//是用Root截图if(new File(filePath[m]).exists()){runtime.exec("cmd /c start "+filePath[m]+"");WindowsTitle = filePath[m].substring(filePath[m].lastIndexOf("/")+1,filePath[m].length());//目录已打开 等待截图Thread.sleep(2000);String fileName = screen_shot(robot,new File(screenPath+WindowsTitle+".png"));newPathInfo[filePath.length + m - 3] = "file://"+screenPath+fileName;Thread.sleep(2000);String windowsCloseBat = "mshta \"javascript:wnds=new ActiveXObject('Shell.Application').windows(); for (i=0; i<wnds.Count; i++) {w=wnds(i); if(w) if(w.document) if(w.document.folder) if('"+WindowsTitle+"'==w.document.folder.title) w.quit();} close();\""+"\r\n" + "exit";String batName = batdir.getAbsolutePath()+"\\"+WindowsTitle + ".bat";//写入批指令WriteFile(new File(batName),windowsCloseBat);//执行批命令 并关闭dos窗口runtime.exec("cmd /c start "+batName+"");}else{System.out.println(filePath[m] + "不存在!");newPathInfo[filePath.length + m - 3] = "路径不存在";new File(filePath[m]).mkdirs();continue;}}}System.out.println("完成"+(i) + "/" + (allPath.size() - 1));allPath.set(i,newPathInfo);}//输出allPathString newContent = "";for(int i = 0 ; i < allPath.size() ; i ++){for(String line : allPath.get(i)){newContent += line + ",";}newContent += "\r\n";}WriteFile(new File(overPath),newContent);}public static void WriteFile(File _file,String content){try {//乱码BufferedWriter bw = new BufferedWriter(new FileWriter(_file));bw.write(content);bw.newLine();bw.close();} catch (IOException e) {e.printStackTrace();}}public static String screen_shot(Robot robot,File screenFile) {Rectangle screenRect = new Rectangle(0, 0, screenSize.width, screenSize.height);//这里可以自己设置图片范围//截图BufferedImage bufferedImage = robot.createScreenCapture(screenRect);//保存截图try {ImageIO.write(bufferedImage, "png", screenFile);} catch (IOException e) {e.printStackTrace();}return screenFile.getName();}public static List<String[]> resolveFile(File csv) {List<String[]> list = new ArrayList<String[]>();try (InputStream csvIs = new FileInputStream(csv)) {CsvReader csvReader = new CsvReader(csvIs,Charset.forName(EncodingUtil.detect(csv)));while (csvReader.readRecord()) {String[] temp = csvReader.getValues();list.add(temp);}} catch (Exception e) {e.printStackTrace();}return list;}
}
mshta "javascript:wnds=new ActiveXObject('Shell.Application').windows(); for (i=0; i<wnds.Count; i++) {w=wnds(i); if(w) if(w.document) if(w.document.folder) if('b07963c07d7b42658ca9ad087fc7cdc4'==w.document.folder.title) w.quit();} close();"
exit
DOS BAT关闭文件夹相关推荐
- BAT 遍历文件夹和子文件夹下所有文件
BAT 遍历文件夹和子文件夹下所有文件 参考网址:http://www.cnblogs.com/tangxin-blog/p/5703146.html echo off & color 0A ...
- dos命令删除文件夹和文件的方法
在dos命令删除文件夹或文件,先要确定文件夹或文件是否有特殊的属性,比如"系统"."只读"."隐藏",如果有,去掉这些属性,命令如下 文件夹 ...
- bat 复制文件夹_新建366个文件夹,你用了2小时,我使用excel与bat命令1分钟搞定...
Hello,大家好,今天跟大家分享下,我们如何使用excel与bat命令为2020年的每天都新建一个文件夹,他的操作也并不难,下面就让我们来一起操作下吧 一.填充日期 想要为2020年的每一天都新建一 ...
- DOS的建文件夹,移动图片,多级文件夹建立
dos 提取文件夹下所有的文件名 1.新建一个.txt文件,输入内容: @echo off dir /s/b *.* > 文件名.xls exit pause 把后缀txt改为bat,有时需要调 ...
- bat 复制文件夹_Windows批量创建文件夹:用Excel和记事本这2个就够了
有时候出于工作需要,要在一个目录下创建大量的文件夹存放一些资料,或者分类整理某些文档, 如果是一个两个文件夹,手动建立是无所谓的,但是如果是十几个文件夹甚至大到上百个文件夹呢? 像是公司需要为几十个人 ...
- bat 复制文件夹_怎么生成电脑上文件夹的目录结构
有时我们会看见有人发布这样的内容: 这个是电脑上一个文件夹的目录结构,用于显示文件夹里各个文件的名称.怎么生成这样的目录呢? 一.按住shift键,右击你要生成目录的文件夹,选择"在此处打开 ...
- 关闭文件夹或打印机共享服务器,局域网共享打印机好用,但文件夹不能访问
(1)NWlink IPX/SPX/NetBIOS Compatible Transport Protocol协议.本协议已经安装就绪,没有问题. (2)开启guest账号:右击我的电脑\管理\用户有 ...
- bat 复制文件夹_一个神奇的bat批处理文件,更好的隐藏电脑里的文件或者文件夹...
在之前和大家分享了如何隐藏电脑上不希望别人看到的文件或者文件夹,具体的分享了两种方法: 1.利用文件或者文件夹本身的隐藏属性进行隐藏文件或者文件夹,此方法很简单但是隐藏的文件很容易被找到! 2.通过c ...
- dos命令进入文件夹
输入 D: 回车,进入D盘的根目录,然后输入dir 回车 可以查看根目录下的文件和文件夹, 输入 cd空格文件夹的名字(不区分大小写) 进入文件夹根目录下,依次输入dir 查看该目录下的文件和文件夹. ...
最新文章
- 清华大学梁宸计算机系,应用数学专业论文
- RabbitMQ 入门
- 为什么手机上传图片这么慢 前端_怎样在手机上就能把图片压缩到100K以下?
- Linux C中内联汇编的语法格式及使用方法
- javascript php 界面,js实现卡片式项目管理界面UI设计效果_javascript技巧
- perl的几个小tips
- 清华大学python教材怎么样_经典!清华大学计算机系教材曝光:《Python编程金典》...
- Word插入参考文献
- r7000屏幕亮度linux,联想legion R7000笔记本linux使用体验
- [毕业设计] 基于单片机的智能快递柜设计与实现 - stm32 物联网
- 【Day5.1】在坑人的免税店King Power蹭午餐
- 阿里云服务器被挖矿程序侵入问题
- c语言printf格式限定符,c – 1字节有符号数的printf格式
- 计算机二级备考:Word 部分_3 表格 长文档综合排版 文档 共享
- 呼叫中心座席人员如何把控时间
- vue导出word纯前端实现
- 58同城产品2面面经
- 为什么建议大家一定要办一张大流量卡!
- WebApi系列~通过HttpClient来调用Web Api接口
- JNLP文件具体说明编辑