Finding a folder and renaming it...

I am trying to find a way to find a folder only by knowing the first word in the folder name then renaming the entire folder…

No one? Sorry I am stumped…

Some of us are sleeping :wink:

begins with and every folder is an good way to filter out folders that does begins with a certain string.

tell application "Finder" to get name of every folder whose name begins with "s"

How do I set the folder I want to look in for that folder? That assumes desktop… All the things I try I get errors trying to say of folder x I am trying to look down deep into sub folders all based on variables. I have the folders currently concatenated into path that format like this /Volumes/xxx/xxxx/xxxx and Volumes:xxxx:xxxx:xxxx

NVM I got it…

set theFolder to (get every item of folder (varPosixProdSubCatPath) whose name begins with varGraphicPartNum) as string

Using the Finder will be slow unless you have very few items in the search folder.


do shell script "find ~/test_directory/ -type d -iname \"move*\""
  • Requires a posix path for the search folder, and if the path has spaces in it quoted form of posix_path

“find ~/test_directory/” I assume this is the path point that contains the folder I am searching?

Yes my did has spaces I would have to account for that.

-type d -iname "move*"" and this is the word I want to search on?

Hello.

You can’t use “~” if you have spaces in the root folder name, but have to spell it from “/Users” to the root folder in question, before you use quoted form of. (But you have to use quoted form if it contains spaces.)

I have made the snippet a little bit more friendly, if fpath is “” then noone where found.

set rootFolder to "~/Desktop/junk"
set folderName to "more_test"
try
	set fpath to first paragraph of (do shell script "find " & rootFolder & " -type d -iname  " & quoted form of (folderName & "*"))
on error
	set fpath to ""
end try

Hey Fousthvk,

Lot’s of ways to do this little job. This one is a trifle more friendly.


set _path to quoted form of (POSIX path of ((path to home folder as text) & "test_directory"))
set findStr to "move*"

set _cmd to "find " & _path & " -depth 1 -type d -iname \"" & findStr & "\" | sed -n '1p'"
set _dir to do shell script _cmd
if _dir ≠ "" then
	# Proceed...
end if

-depth 1 == stops recursive search.
-type d == looks only for directories.
-iname == case-insensitive name search.
“move*” == search for name starting with ‘move’ with wildcard character ‘*’ denoting anything else.

The tacked-on ‘sed’ command will return only the first found paragraph.

The way I’d do this on my system is to use the Satimage.osax

set srchPath to alias ((path to home folder as text) & “test_directory”)
set dirList to glob “[mM][oO][vV][eE]*/” from srchPath as alias