POSIX puzzle

When I use a shell script to return a list of files, it returns a incomplete path…

set thefolder2 to quoted form of POSIX path of (choose folder)
set filelist to paragraphs of (do shell script “find " & thefolder2 & " -iname *.jpg | tr -s ‘/’”)
–Return
{“/30720/307200001.jpg”, “/30720/307200002.jpg”, “/30720/307200003.jpg”, “/30720/307200004.jpg”, “/30720/307200005.jpg”, “/30720/307200006.jpg”}

Please tell me how to make it return a complete path in filelist.

Thanks,
Mark

This will convert the paths to full, colon delimited paths. Is that what you need?

set thefolder2 to quoted form of POSIX path of (choose folder)
set filelist to paragraphs of (do shell script "find " & thefolder2 & " -iname *.jpg | tr -s '/'")

set full_paths to {}
repeat with item_ in filelist
	set end of full_paths to item_ as POSIX file as text
end repeat

– Rob

Where does the extra ‘/’ come from? I was looking at this and discovered that applescript puts an extra ‘/’ in the path, hence the need to pipe the output through tr -s.

If I run the command:
find /directory/path -iname *.jpg
in the terminal, I get:
/directory/path/file1.jpg
/directory/path/file2.jpg
/directory/path/file3.jpg

but
do shell script “find /directory/path -iname *.jpg”
yields
/directory/path//file1.jpg
/directory/path//file2.jpg
/directory/path//file3.jpg

Andy

Thanks for your help, yes it was exactly what I needed.

Now if I can expand the question/puzzle further…

The script I am making is renaming and moving files, it looks in a folder and finds every .jpg file. Then it renames every file to [top-foldername][5 digit counter].jpg, but doing this in Finder is a very consuming task.
Can it be done using shell scripting ?

Where can I find some more info on shell scripting ? I tried looking at apple.com but no luck.

Again, thanks for all you help.

–script start
global theCounter

on open theItems
set startTime to (current date)
repeat with aFolder in theItems
if folder of (info for aFolder) then doIt(aFolder)
end repeat
set finito to false
repeat until finito
beep
set usr1 to display dialog ((((current date) - startTime) as text) & " sekunder.“) buttons {”•"} default button 1 with icon note giving up after 5
if button returned of usr1 is “•” then set finito to true
end repeat

end open

on run
doIt(choose folder)
end run

on doIt(aFolder)
set theCounter to 0
tell application “Finder” to set parentName to the name of aFolder

set thefolder2 to quoted form of POSIX path of aFolder
set filelist to paragraphs of (do shell script "find " & thefolder2 & " -iname *.jpg | tr -s '/'")
set full_paths to {}
repeat with item_ in filelist
	set end of full_paths to item_ as POSIX file as text
end repeat
set AppleScript's text item delimiters to ":"

repeat with aFile in full_paths
	
	tell application "Finder" to move (aFile as alias) to aFolder
end repeat
set filelist to paragraphs of (do shell script "find " & thefolder2 & " -iname *.jpg | tr -s '/'")
set full_paths to {}
repeat with item_ in filelist
	set end of full_paths to item_ as POSIX file as text
end repeat
repeat with aFile in full_paths
	set theCounter to countUp()
	set newName to (parentName & theCounter & ".jpg")
	tell application "Finder"
		set the name of (aFile as alias) to newName
	end tell
end repeat
set AppleScript's text item delimiters to ""

end doIt

on countUp()
set theCounter to theCounter + 1
set tc to theCounter as text
repeat until (count of characters of tc) is 5
set tc to (“0” & tc)
end repeat
return tc
end countUp
– end script

I’m sure that it can be done quickly in the shell but I’m not familiar enough with the shell to offer advice. Hopefully someone else can offer guidance.

– Rob

Rob, thanks for your help.
Do you know where to pick up some documentation on shell scripting ?

Cheers,
Mark

There are dozens, if not hundreds, of shell apps that are available to perform a wide variety of tasks and it’s sometimes difficult for a shell beginner (like me) to figure out which is the best tool for a given job. This thread offers a couple of sources of info.

Good luck!

– Rob