Move files from a List

I want to move files from a folder to another one based on a text list.
My source folder is big, it has more than 2000 files.
I want to move around 200-300 files (listed in my text list)
to the destination folder

I would like something like this:

  • Choose source folder
  • Choose destination folder
  • Select txt file to read

My files are like this:
canarinha.doc
picapau.xls
canarinha.xls
lembranca.txt
picapau.doc
porta-486.jpg
89.txt

attention: some files have same name but different extension
my textlist lists the names with extension like:
canarinha.xls
picapau.doc
(move only these ones)

highly appreciated your help

Model: macbrook pro 2010
AppleScript: 2.6.1
Browser: Safari 537.36
Operating System: Mac OS X (10.9)

As you didn’t wrote if the folders are on the same device or if they aren’t, I post two versions.

# folders in the same device
set path2source to choose folder with prompt "Select the source folder" default location (path to desktop)
set path2dest to choose folder with prompt "Select the destination folder" default location (path to desktop)
set path2list to choose file with prompt "Select your textList" of type {"txt"}

set theList to paragraphs of (read path2list)

tell application "Finder"
	set theNames to name of files of path2source
	repeat with aName in theNames
		if (aName as text) is in theList then
			move file aName of path2source to path2dest
		end if
	end repeat
end tell
# folders on different devices
set path2source to choose folder with prompt "Select the source folder" default location (path to desktop)
set path2dest to choose folder with prompt "Select the destination folder" default location (path to desktop)
set path2list to choose file with prompt "Select your textList" of type {"txt"}

set theList to paragraphs of (read path2list)

tell application "System Events"
	set theFiles to path of files of path2source
	set sourceList to {}
	repeat with aFile in theFiles
		if (name of disk item aFile) is in theList then
			set end of sourceList to my quotedIt(aFile)
		end if
	end repeat
end tell

do shell script "mv " & my recolle(sourceList, space) & space & quoted form of POSIX path of path2dest

#=====

on quotedIt(aFile)
	return quoted form of POSIX path of aFile
end quotedIt

#=====

on recolle(l, d)
	local oTIDs, t
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

#=====

As you use 10.9, no need for a version using ASObjC.

Yvan KOENIG running Sierra 10.12.4 in French (VALLAURIS, France) mardi 11 avril 2017 10:32:16

Mr. Yvan, thank you very much for your help

I run the 2 applescripts you provided but say that “theList.txt” no found
My knowledge of coding is none. I am sorry.

It would be a way the applescript ask me

  • Select the source folder?
  • Select the target folder?
  • Select your textList?

In reference of the folders: the source folder and the target folder always are in the same device. Sometimes in my computer, sometimes in different external hard disks.

Sorry for my bad english

appreciated your help

I edited the scripts in my first message.

The second script may be used in both cases.
As it triggers “do shell script” only once I guess that it’s not slower than the first one.
I have no practice of do shell script moving 300 files in a single call.
I don’t know if there is a limit to the length of such a command.

Yvan KOENIG running Sierra 10.12.4 in French (VALLAURIS, France) mardi 11 avril 2017 17:03:04

Thank you very very much. This is what I need
I tried with your second script as you suggested.
with +2000 files and moving 500 files, it took less than a minute.
Muito obrigado!

Thanks for the feedback.
I learnt something.

Yvan KOENIG running Sierra 10.12.4 in French (VALLAURIS, France) mardi 11 avril 2017 19:30:51