Created
August 10, 2013 13:20
-
-
Save KxNxT/6200422 to your computer and use it in GitHub Desktop.
photo moved by date.
windowsでうまくeachが動かなかった?のでfor文を使ってる。 作成日付を元にファイルを移動する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
require 'rubygems' | |
require 'find' | |
inDir = "C:/Users/KENT/Pictures/old/" | |
outDir = "C:/Users/KENT/Pictures/new/" | |
list = [] | |
Find.find(File.expand_path(inDir)){ |path| | |
if /.*(jpg|JPG|jpeg|JPEG|mp4|MP4|png|PNG|wmv|mov|MOV|DNG|AVI|gif|GIF|avi|ASF)\z/ =~ path | |
list << path | |
end | |
} | |
Dir.mkdir(outDir) unless File.exist?(outDir) | |
for num in 0..list.size - 1 do | |
path = list[num] | |
foldername = File::mtime(path).strftime('%Y%m') | |
folderpath = outDir + foldername | |
Dir.mkdir(folderpath) unless File.exist?(folderpath) | |
p path + " >>> " + folderpath + File::mtime(path).strftime('/%Y-%m-%d_') + File::basename(path) | |
FileUtils.mv(path, folderpath + File::mtime(path).strftime('/%Y-%m-%d_') + File::basename(path)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment