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关闭文件夹相关推荐

  1. BAT 遍历文件夹和子文件夹下所有文件

    BAT 遍历文件夹和子文件夹下所有文件 参考网址:http://www.cnblogs.com/tangxin-blog/p/5703146.html echo off & color 0A ...

  2. dos命令删除文件夹和文件的方法

    在dos命令删除文件夹或文件,先要确定文件夹或文件是否有特殊的属性,比如"系统"."只读"."隐藏",如果有,去掉这些属性,命令如下 文件夹 ...

  3. bat 复制文件夹_新建366个文件夹,你用了2小时,我使用excel与bat命令1分钟搞定...

    Hello,大家好,今天跟大家分享下,我们如何使用excel与bat命令为2020年的每天都新建一个文件夹,他的操作也并不难,下面就让我们来一起操作下吧 一.填充日期 想要为2020年的每一天都新建一 ...

  4. DOS的建文件夹,移动图片,多级文件夹建立

    dos 提取文件夹下所有的文件名 1.新建一个.txt文件,输入内容: @echo off dir /s/b *.* > 文件名.xls exit pause 把后缀txt改为bat,有时需要调 ...

  5. bat 复制文件夹_Windows批量创建文件夹:用Excel和记事本这2个就够了

    有时候出于工作需要,要在一个目录下创建大量的文件夹存放一些资料,或者分类整理某些文档, 如果是一个两个文件夹,手动建立是无所谓的,但是如果是十几个文件夹甚至大到上百个文件夹呢? 像是公司需要为几十个人 ...

  6. bat 复制文件夹_怎么生成电脑上文件夹的目录结构

    有时我们会看见有人发布这样的内容: 这个是电脑上一个文件夹的目录结构,用于显示文件夹里各个文件的名称.怎么生成这样的目录呢? 一.按住shift键,右击你要生成目录的文件夹,选择"在此处打开 ...

  7. 关闭文件夹或打印机共享服务器,局域网共享打印机好用,但文件夹不能访问

    (1)NWlink IPX/SPX/NetBIOS Compatible Transport Protocol协议.本协议已经安装就绪,没有问题. (2)开启guest账号:右击我的电脑\管理\用户有 ...

  8. bat 复制文件夹_一个神奇的bat批处理文件,更好的隐藏电脑里的文件或者文件夹...

    在之前和大家分享了如何隐藏电脑上不希望别人看到的文件或者文件夹,具体的分享了两种方法: 1.利用文件或者文件夹本身的隐藏属性进行隐藏文件或者文件夹,此方法很简单但是隐藏的文件很容易被找到! 2.通过c ...

  9. dos命令进入文件夹

    输入 D: 回车,进入D盘的根目录,然后输入dir 回车 可以查看根目录下的文件和文件夹, 输入 cd空格文件夹的名字(不区分大小写) 进入文件夹根目录下,依次输入dir 查看该目录下的文件和文件夹. ...

最新文章

  1. 清华大学梁宸计算机系,应用数学专业论文
  2. RabbitMQ 入门
  3. 为什么手机上传图片这么慢 前端_怎样在手机上就能把图片压缩到100K以下?
  4. Linux C中内联汇编的语法格式及使用方法
  5. javascript php 界面,js实现卡片式项目管理界面UI设计效果_javascript技巧
  6. perl的几个小tips
  7. 清华大学python教材怎么样_经典!清华大学计算机系教材曝光:《Python编程金典》...
  8. Word插入参考文献
  9. r7000屏幕亮度linux,联想legion R7000笔记本linux使用体验
  10. [毕业设计] 基于单片机的智能快递柜设计与实现 - stm32 物联网
  11. 【Day5.1】在坑人的免税店King Power蹭午餐
  12. 阿里云服务器被挖矿程序侵入问题
  13. c语言printf格式限定符,c – 1字节有符号数的printf格式
  14. 计算机二级备考:Word 部分_3 表格 长文档综合排版 文档 共享
  15. 呼叫中心座席人员如何把控时间
  16. vue导出word纯前端实现
  17. 58同城产品2面面经
  18. 为什么建议大家一定要办一张大流量卡!
  19. WebApi系列~通过HttpClient来调用Web Api接口
  20. JNLP文件具体说明编辑

热门文章

  1. 在FlowDocument中设置TableCell垂直居中遇到的问题
  2. 程序员与算法的羁绊,是几世以前就定下的
  3. 新年烟花(有倒计时)
  4. 保姆级教程,手把手教你批量打造小红书爆文笔记,快来收藏
  5. 用 CSS 画个小企鹅
  6. 黑马程序员--OC内存管理机制(上)
  7. nsq Android客户端,NSQ源码-Nsq客户端
  8. web前端JavaScript程序员必学技术指南
  9. JVM原理-垃圾回收机制及算法
  10. C++移动拷贝构造函数