Tuesday, April 28, 2009

How to Rename Files En Masse

Recently, I was confronted with a rather large batch of image files that needed renaming. There were several hundred, and it would have taken far too long to do it manually. So, I wrote a short Python computer program that will do this in a matter of seconds.

If you also ever need to rename many files and don't want to do it manually, you can use this same technique (no experience necessary).

This example is provided as is. Please don't send me your angry email if you accidentally rename all the files on your computer and nothing works anymore. Follow the directions carefully.

Follow these steps.

1) Make a complete copy of all the files that need renamed and save them to a new folder. You can't undo this renaming thing so you don't want to take the chance that all your files get renamed incorrectly. Back them up and be safe. Nothing but the files to be renamed should be in the new folder. Call the folder "rename"

2) Download Python from their website and install it: http://www.python.org/

3) Download Komodo Edit from their website and install it: http://www.activestate.com/komodo_edit/

4) Read Chapters 1-3 of Bill Turkel's "Programming Historian" and set up Komodo Edit to have a 'Run Python' feature (it's in the chapter. Read it! It will only take 10 minutes).

5) Open Komodo Edit and create a new file. Save it as Rename.py .

6) Paste the following code into that file. Indenting is important:


#!/usr/bin/env python
import os
from os import rename

x = os.listdir('C:\\Documents and Settings\\Replace with Path to Folder')
print x
a = 0
b = 0
for file in x:
    if x[a].find(".tif") != -1:
        print a
        os.rename(x[a], 'newName-' + str(b) + '.tif')

#end code

7) Three lines need to be changed.
a) x = os.listdir('C:\\Documents and Settings\\Replace with Path to Folder')
change this to have the path of your folder containing the files to be changed. Make sure you use two slashes between directory layers, not one. The first slash is actually an "escape" character that tells the program to consider the 2nd slash as an alphanumeric character rather than a code character with special meaning.
You can find the path of your folder by right clicking it and selecting properties.

b) if x[a].find(".tif") != -1:
Replace ".tif" with whatever type of file you are changing the name of. This can be any file type you like. .jpg, .txt, .html, etc.

c) os.rename(x[a], 'newName-' + str(b) + '.tif')
Replace "newName" with whatever you want to change the name to, and ".tif" to whatever file format you selected in step (b). This is a pretty simple program - if you go through it line-by-line you can probably figure out what each step does.

8) Resave the file. Place Rename.py in the same folder as the files that you want renamed. Treat this program like a loaded gun. You don't want to run it in the wrong folder. If you run it will rename everything in that folder whether you want it to or not. As long as you don't double click it you should be ok.

9) Open Rename.py in Komodo Edit and run the program using the technique described in the Programming Historian's "Hello World" example.

You should now have an entire folder full of renamed files. They will be named "newName1.tif", "newName2.tif", etc. Notice that the old names are now completely gone.

This can save you a lot of time if you're dealing with hundreds of files. But, please be careful. Don't rename any files that are critical to your system.

A little bit of computer programming can go a long way

Friday, April 17, 2009

How Researchers can Effectively use Twitter

I've been getting a lot of questions lately by friends and colleagues who wonder how and why I use Twitter. Most of these people seem to assume that I'm tweeting what I had for breakfast (or hoping to find out what the CHNM staff had for breakfast). To these people social media is a place where you post pictures of your drunk friends from last night, divulge far too much personal information and take tests that tell you which type of car you are.

There are certainly users of both Facebook and Twitter that have propelled these stereotypes along, but there are definitely good, professional and educational uses for Twitter. One of the best examples of this is the digital humanities community.

I've decided to only use Twitter as a professional learning tool. I don't seek out social friends, am not helping Brit reach 1 million followers (even if there might be a pair of concert tickets in it for me) and actively "unfollow" people who send throngs of breakfast related messages. That has left me with a small but active group of people who provide a steady stream of helpful and insightful information to me every day. Here are the types of tweets I find most helpful as a researcher and digital humanist:

1) Conference Streaming
These live, on the go tweets come from people attending a conference or public lecture. They provide an outline of what a person is presenting, along with interesting excerpts from the audience or thoughts the tweeter may have. Often, these tweets include links to the presenter's slides or notes. While not nearly as good as attending a presentation yourself, this is a big first step in reducing the ephemeral nature of the podium speech and disseminating it to those of us who could not attend, or might not think to attend.

2) Interesting & Relevant Links
With so many people writing in so many places, it's impossible to notice everything. Tweets routinely point me to blog posts, journal articles and webpages relevant to my research - as long as you're following the right people.

3) Finding other Digital Humanists
Around last year at this time I was pretty sure Bill Turkel and Dan Cohen were the only two digital humanists on the planet. Through Twitter, I've found a few dozen more and have stumbled upon research that has both amazed me and prompted new avenues for my own study. For those twitterers interested in Digital Humanities, make sure you check out those listed under #digitalhumanities on http://wefollow.com .

4) Project Updates
Some of the people I follow aren't people at all. Many organizations create twitter accounts for their projects / institutions and send out tweets to let people know of upgrades / upcoming events. It's easy to go overboard with these types of tweets, so I have to say I always appreciate those organizations who exercise discretion and only tweet about significant news.

5) Crowdsourcing
Need a second opinion? Looking for a piece of software that does something obscure? I've found plenty of both by sending out a tweet and waiting for the expertise of my followers to kick in with suggestions.

And the last thing I have found it useful for is getting my own message out. A few weeks ago I posted a message on this blog about my Zotero translator guide and walked away. Within an hour, twitterers has noticed my post and tweeted it across the twittersphere. Over the next couple days I received a few hundred visitors, directly because of the tweets and the internet had been seeded with links (in more than one language) pointing people to the resource I had created. If I had sought traditional, print based forms of publishing, I'd probably still be waiting months for the presses to roll.

Twitter lets me keep up to date with research and developments amongst people with like interests. If done prudently, you can avoid the drunk photos, tests about what car you are and information about what everyone had for breakfast.

Incidentally, I had an apple cinnamon toaster's strudel this morning. And on Mondays, the whole staff of CHNM eats bagels. Ahhh, how I miss those bagels.

Wednesday, April 1, 2009

How Best to Approach Academic Journals

Are you a humanist trying to get published in an academic journal? Trying to decide if it's worth the time and effort? Do you know someone who fits this category?

The round table discussion (audio) at the American Society for Environmental History, recorded in Talahassee this past month, offers some excellent tips for grad students and post docs. The round table was made up of editors from several academic journals and offers insights into what they like, what they hate, what to do and what not to do. A must listen for any grad student and a great recommendation for any prof to give to their students. Don't let the environmental history topic scare you away; it doesn't factor into the equation at all. This recording is useful for anyone in the humanities; including profs with poor writing skills.