delete from list (textfile)

I am working on a sript that deletes files from a list in a textfile.
What I want to edit to this script that it deletes files whose names start with the names in the list.
example: delete xxxxx.xxx and also xxxxx.xxx.xxx

This is what I have soo far:


set processFolder to choose folder with prompt "Kies folder" without invisibles

tell application "Finder"
	if not (exists folder "REMOVED" of processFolder) then
		make new folder at processFolder with properties {name:"REMOVED"}
	end if
	set the destination_folder to folder "REMOVED" of processFolder as alias
end tell

set chosenfile to (choose file) as Unicode text

try
	set openfile to open for access chosenfile
	set filecont to read openfile
	close openfile
on error errmsg number errnum
	try
		close access openfile
	end try
	error errmsg number errnum
end try

set filenames to paragraphs of filecont

repeat with filename in filenames
	if length of filename is greater than 0 then
		tell application "Finder"
			try
				move (every file of entire contents of processFolder whose name is in filenames) to destination_folder with replacing
			end try
		end tell
	end if
end repeat

display dialog "Done" buttons {"OK"} default button 1

Thanks in advance,

Peter

Hi Peter,

first of all, it would be better, if you could explain more exactly, which errors or outputs your script produces (or not)
Next time :wink:

Your problem:
Finder tries to compare the name of every file with your ‘filenames’ which is a LIST!!!
See Event Log in Scripteditor.
But with your repeat loop you can easily select ONE name in your list (as you already do by saying “repeat with filename in filenames”) and compare it with the files in the folder. That’s the purpose of a loop; picking up items one by one.

So this would do the job:

move (every file of entire contents of processFolder whose name contains filename) to destination_folder with replacing
-- Look: it is "filename" not "filenames"

better in your case:

move (every file of entire contents of processFolder whose name starts with filename) to destination_folder with replacing

Hope you understand my explanation.

Bye
Wiggum

Thanks a lot for the explanation!!
It works just fine now.

By the way,
I have another post called “replace files in (sub)folders -REPOST, PLEASE HELP!!!”
If you have the time could have a look at it because it goes way beyond my scripting capabilities
and the number of file I need to replace (weekly) is HUGE.

Thanks for helping me out!!

– Peter –