Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread Display Modes
Old Dec 26, 2006, 07:45 PM   #1
macrumors newbie
Join Date: Dec 2006
Duplicate Folder and Rename Files

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:

and it needs to be:
sinfulboi is offline   0 Reply With Quote
Old Dec 26, 2006, 08:56 PM   #2
macrumors 6502a
Join Date: Apr 2005

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.
Mac_Freak is offline   0 Reply With Quote
Old Dec 26, 2006, 10:15 PM   #3
macrumors member
Join Date: Jun 2005
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 ./ dir_to_be_copied
Hope it helps.
#!/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'

tmp = os.getcwd().split(os.sep)
oldcwd = tmp[len(tmp) - 1]
newdir = '../' + oldcwd + '_copy' 
if not (oldcwd + '_copy') in os.listdir(os.pardir):
for a in os.listdir(os.curdir):
	os.system("cp " + a + " " + newdir + "/" + change(a))
wala is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Renaming files in OS X 10.7 Lion benjancewicz Mac OS X 10.7 Lion 5 Mar 31, 2012 12:19 PM
Lion wont auto arrange folder and files. Xavio OS X 5 Oct 11, 2011 12:30 PM
moved-aside folder and empty files in XCode ohbrilliance Mac Programming 2 Jan 30, 2010 12:29 PM
Software to find duplicate audio and image files gasport Mac Applications and Mac App Store 1 Apr 27, 2009 02:08 PM

All times are GMT -5. The time now is 07:51 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013,, LLC