Copying filenames to new files

Hi all. I’ve spent ages searching for something like this, but can’t find quite the right thing …

Basically, I have a list of files in a folder, and I wish to copy the filenames from all these files and paste them onto new files in a different folder.

Is there a simple Applescript to do this?

Thanks in advance.

This works if you have the same number of files in each folder:

set sourceFolder to POSIX file "/Users/Dave/Desktop/Source" as alias
set destFolder to POSIX file "/Users/Dave/Desktop/Destination" as alias

tell application "Finder"
	set sourceFolderNames to name of every file of sourceFolder
	set destFolderItems to every file of destFolder
	repeat with i from 1 to count of destFolderItems
		set name of item i of destFolderItems to item i of sourceFolderNames
	end repeat
end tell

What do you want to do it for?

Excellent, thank you, I’ll give it a go.

I’m using it to replace around 200 images on a website. They’re all subtly different, but I need to be able to upload them without disrupting the live site “ hence the need for new files with identical names to the old files.

I have tried a sample using a manual cut/paste job, but after about 70 images or so, I ended up with a discrepancy in the number of original/new files “ then I though “Hey … I bet there’s an Applescript for this” !

Many thanks again.

That worked perfectly.

I tried to add a ‘choose folder’ prompt in place of the absolute path in your script, but get the error “Can’t make POSIX file (alias … into type alias.” I’ve tried a few combinations of alias and string etc, but no luck. Admittedly, I’m no expert!

What should I do to enable choosing of the source and destination folders (so I can use it for different sites without hard-coding the file paths)?

Choose folder results in an alias anyway:

set sourceFolder to choose folder

Post your script and we might be able to see what has gone wrong (and right).

Ah I see. That did it.

I had used the following:

set sourceFolder to choose folder with prompt "Select the folder of source files to copy from ." as alias

I just took the “as alias” off the end and it worked. I’m still getting my head around when and why to use POSIX, alias etc, and when and which to pass to the various parts of my scripts.

Many thanks again for your help. No doubt, I’ll be back!