April 30, 2008 at 7:09 pm
· Filed under Python, Random Things
Here’s a little script I created to copy all of the covers from my mp3 folders over to my flac folders. It also came in handy a few days ago when I accidentally deleted all of the covers that were present on my Sansa.
#! /usr/bin/env python
import os
import sys
import shutil
import string
for root, dir, files in os.walk(sys.argv[1]):
if len(dir) == 0:
copy_from = sys.argv[2] + '/' + root.replace(sys.argv[1],'').translate(
string.maketrans(':<>\|*?','_______'))
try:
for file in os.listdir(copy_from):
if file == '.directory' or file.endswith(('.jpg','.jpeg','.png','.gif','.bmp')):
copy_file = copy_from + '/' + file
shutil.copy(copy_file, root)
except OSError: pass
Permalink
March 3, 2008 at 2:38 pm
· Filed under Random Things, Ruby
Have you ever had to move a lot of files from a sane filesystem to one that behaves more like FAT? Do these files have “strange” characters in their names, such as ‘:’, ‘?’, or ‘*’? This simple utility can rename these files so that the FAT-invalid characters are replaced with ‘_’. Works great for “fixing” the filenames on your music collection before transferring it to your portable audio player. You can download it here.
#!/usr/bin/env ruby
require 'find'
bad_str = ":<>\\|*?\""
bad_files = Array.new
Find.find(ARGV[0]) do |file|
bad_files.push file
end
# reverse array so bad directories come after the files
bad_files.reverse!
bad_files.each do |file|
basename = File.basename(file)
if basename.count(bad_str) > 0
dirname = File.dirname(file)
new_file = File.join(dirname, basename.tr(bad_str, '_'))
puts [file, ' -> ', new_file].join
File.rename( file, new_file )
end
end
Permalink
October 30, 2007 at 8:20 am
· Filed under Nintendo, Random Things
Sparked by a trip to SuperFresh to get some biscuits for dinner, I came across some huge pumpkins for $3. Thus, I was inspired to create a nerdy pumpkin for Halloween. I did all the carving with my Dremel rotary tool and a dinner knife. To keep it from rotting, I covered it in WD-40.
Read the rest of this entry »
Permalink
June 15, 2007 at 11:27 am
· Filed under Random Things
Permalink