Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sinfulboi

macrumors newbie
Original poster
Dec 22, 2006
4
0
i know this may sound like a common problm but i just can not figure it out... i have a folder on my desktop that i need to duplicate and then totally rename all the files is it... i dont want to add a string to the start or the end... i want to do this on a regualar basis as the folder contains text files i download regulary.

for example the original files as:
/Desktop/downloads/filename_1.txt
/Desktop/downloads/filename_2.txt
/Desktop/downloads/filename_3.txt
/Desktop/downloads/filename_4.txt

and it needs to be:
/Desktop/downloads_copy/001.txt
/Desktop/downloads_copy/002.txt
/Desktop/downloads_copy/003.txt
/Desktop/downloads_copy/004.txt
 

Mac_Freak

macrumors 6502a
Apr 22, 2005
713
0
Automator

If you are using Tiger then Automator will do most of the work for you. Just create a Finder plug-in/script that will rename selected items. All you will have to do is to duplicate the folder (right click > duplicate) and select all the files in that folder and and pick your scrip from Automator submenu in contextual menu (right-click). And pick your options.

I think, but I am not sure, but you could also create a folder action that will do that.
 

wala

macrumors member
Jun 3, 2005
46
0
Here's a Python script which will move all files named to the new directory (which is the name of the old directory + "_copy") and rename them to '00#.txt'. If you don't know how to use python or the terminal then someone can create a GUI applescript wrapper for it.
The script assumes all files to be copied are in the format the "file name + a number + '.txt'".
usage is ./script.py dir_to_be_copied
Hope it helps.
Code:
#!/usr/bin/env python

import string
import os
import sys

def change(str):
	str = str.split('.')[0]
	oldstr = str
	i = 1
	str = oldstr[len(oldstr) - i:]
	while (str[0] in string.digits):
		i += 1
		str = oldstr[len(oldstr) - i:]
	str = str[1:]	
	return string.rjust(str, 3, '0') + '.txt'

os.chdir(sys.argv[1])
tmp = os.getcwd().split(os.sep)
oldcwd = tmp[len(tmp) - 1]
newdir = '../' + oldcwd + '_copy' 
if not (oldcwd + '_copy') in os.listdir(os.pardir):
	os.mkdir(newdir)
for a in os.listdir(os.curdir):
	os.system("cp " + a + " " + newdir + "/" + change(a))
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.