最近写的几段小工具代码

来源:互联网 发布:mac怎么连接vps 编辑:程序博客网 时间:2024/05/18 06:28

一、bash路径中的space

#!/bin/bashecho `pwd`bakup=$IFSIFS=`echo -en "\n\b"`for i in $(find . -name "Screen*");donew=${i// /_}#echo ${new}new=${new/Screen_Shot_/}echo ${new}mv ${i} ${new}doneIFS=$bakup

二、大量图片切割

#!/bin/bashpath=$(cd "$(dirname "$0")"; pwd)echo ${path}cd ${path}rm _2016*.pngfor i in $(find . -name "*.png");doconvert $i -quality 100 -crop 480x320+88+106 ${i/2016/_2016}done


三、iphone相册大量图片分割到多个目录(4000张图片,放一个目录预览非常慢!)

import java.io.File;public class What {public static String wrap(int value) {String item = String.valueOf(value);int len = 4 - item.length();StringBuffer sb = new StringBuffer();for (int j = 0; j < len; j ++) {sb.append("0");}sb.append(item);return sb.toString();}public static void main(String[] args) {// TODO Auto-generated method stubString strPath = "/Users/max/Images/iPhone4s/";File dir = new File(strPath);if (!dir.exists()) {System.out.println("Error");return;}StringBuffer sb = new StringBuffer();sb.append("#!/bin/bash\n");sb.append("cd ").append(strPath).append("\n");for (int i = 1; i <= 4000; i += 200) {String from = wrap(i);String to = wrap(i + 199);String result = from + "~" + to;//System.out.println(result);String path = strPath + result;File item = new File(path);if (!item.exists()) {item.mkdir();}for (int j = i; j <= i + 199; j ++) {String haha = "IMG_" + wrap(j) + ".png";File f = new File(strPath + haha);if (!f.exists()) {continue;}sb.append("mv ").append("IMG_").append(wrap(j)).append(".png ");sb.append(result).append(File.separator).append("\n");}}System.out.println(sb);IOBridge.write(sb.toString(), new File("/Users/max/Desktop/start"));}}

0 0