• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Using automator to place hundred of files in a single folder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using automator to place hundred of files in a single folder


  • Subject: Re: Using automator to place hundred of files in a single folder
  • From: David Hoerl <email@hidden>
  • Date: Wed, 30 Jan 2013 16:01:48 -0500

On 1/30/13 2:58 PM, BevInTX wrote:
There are couple issues with this ...

Sigh. Yes. It shows even the simpliest of tasks is never simple. I had tested with a folder having a space, but not everything else, which I did after getting your email.

Note that ksh is good about quoting - you can use "$var" to use it whole.

Note the revised script looks at the original directory entry and only processes the folders (good suggestion).

Taking my own advice, I made it harder to clobber a good folder by asking the user again if they really want to do this, in an AppleScript option as the first action:

---
on run {input, parameters}
	set myDir to ""
	if length of input is not equal to 1 then
tell application "Finder" to display alert "Need One Folder" message "Please drop a single folder on this app"
	else
		set myDir to item 1 of input
		if isDirectory(myDir) is false then
tell application "Finder" to display alert "No Folder" message "Please drop a folder on this app, not a file"
			set myDir to ""
		else
			set rep to ""
			tell application "Finder"
set rep to button returned of (display alert "Consolidate" buttons {"Proceed", "Cancel"} message "Really consolidate folder \"" & myDir & "\"")
			end tell
			if rep is not equal to "Proceed" then
				set myDir to ""
			end if
		end if
	end if
	return myDir
end run

on isDirectory(someItem) -- sometime is a string
	set itemPath to quoted form of (POSIX path of someItem)
	set fileType to (do shell script "file -b " & itemPath)
	if fileType ends with "directory" then return true
	return false
end isDirectory
---

Followed by a /bin/ksh action using parameter input:

---
#rm /tmp/log.txt
#echo "START $1" >> /tmp/log.txt

if [ $# -ne "1" ]
then
	#echo "NOT ONE ARG" >> /tmp/log.txt
	exit 0
fi

d="$1"
if [ ! -d "$d" ]
then
	#echo "NOT A DIRECTORY $d" >> /tmp/log.txt
	exit 0
fi

for f in "$d"/*
do
	#echo DOING f=$f >> /tmp/log.txt
	if [ -d "$f" ]
	then
		#echo DIRECTORY "$f" >> /tmp/log.txt
		find -d "$f" -type f -exec mv -n {} "$d" \;  #-print >> /tmp/log.txt 2>&1
		#echo "MOVED FILES" >> /tmp/log.txt
		find -d "$f" -type d -exec rm -rf {} \;      #-print >> /tmp/log.txt 2>&1
		#echo "REMOVE DIR" "$f" >> /tmp/log.txt
		rm -rf "$f"
	fi
done

osascript -e 'tell application "Finder" to display alert "Consolidate" message "Success!"'
---

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Automator-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Using automator to place hundred of files in a single folder (From: Philip Giles <email@hidden>)
 >Re: Using automator to place hundred of files in a single folder (From: David Hoerl <email@hidden>)

  • Prev by Date: Re: Using automator to place hundred of files in a single folder
  • Next by Date: Re: Using automator to place hundred of files in a single folder
  • Previous by thread: Re: Using automator to place hundred of files in a single folder
  • Next by thread: Re: Using automator to place hundred of files in a single folder
  • Index(es):
    • Date
    • Thread