bat 执行cmd 命令

9 篇文章 0 订阅

1):执行java命令,定时删除指定路径下30天之前的的文件(/k:执行完毕后窗后不关闭)

deletearchivelog.bat

start "" "cmd /k "java DeleteFilesSimpe""

 

DeleteFilesSimpe.class

package com.vtradex.stms.server.utils;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DeleteFilesSimpe {
	public static SimpleDateFormat dmy_hms = 
			new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
	public static void main(String[] args) {
		 String filePath = "D:/app/archivelog";
		while(true){
			int l = moveFileToReady(filePath);
			if(l>0){
				System.out.println(dmy_hms.format(
						new Date())+","+filePath+"----------"+l);
			}else{
				System.out.println(dmy_hms.format(
						new Date())+","+filePath);
			}
			try {
				//1000=1s,1h=60m,1m=60s,10800000=3h,3600000=1h
				Thread.sleep(10800000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	private static Integer moveFileToReady(String fromDir){
		File srcDir = new File(fromDir);
		if (!srcDir.exists()) {
			return 0;
		}
		File[] files = srcDir.listFiles();
		if (files == null || files.length <= 0) {
			return 0;
		}
		int l = 0;
		Date today = new Date();
		for (int i = 0; i < files.length; i++) {
			if (files[i].isFile()) {
				try {
					File ff = files[i];
			        long time=ff.lastModified();
				    Calendar cal=Calendar.getInstance();   
			        cal.setTimeInMillis(time);   
			        Date lastModified = cal.getTime();
			      //(int)(today.getTime() - lastModified.getTime())/86400000;
			        long days = getDistDates(today, lastModified);
			        if(days>=30){
			        	files[i].delete();
			        	l++;
			        }
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return l;
	}
	
	 /** 
     * @param startDate 
     * @param endDate 
     * @return 
     * @throws ParseException 
     */  
    public static long getDistDates(Date startDate,Date endDate)    
    {  
        long totalDate = 0;  
        Calendar calendar = Calendar.getInstance();  
        calendar.setTime(startDate);  
        long timestart = calendar.getTimeInMillis();  
        calendar.setTime(endDate);  
        long timeend = calendar.getTimeInMillis();  
        totalDate = Math.abs((timeend - timestart))/(1000*60*60*24);  
        return totalDate;  
    }  
}

 

2):执行ping命令

cmd.bat

start "" "cmd /k "ping 192.168.1.109""

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值