Get folder instance

Hello everyone. I had a need to move all the items that were in a folder up one level. Like moving ‘file’ from ‘Subfolder’ to ‘Folder with subfolders’:
Folder with subfolders-
Subfolder-
file

You know… this seems like something simple… but I tried for hours and nothing seemed to work (that’s early am programming for you).

I tried:

set containing_folder to (choose folder)
set enclosed_folder to folder of containing_folder whose name contains "blueberry"

tell application "Finder"
	move all items of enclosed_folder to containing_folder
end tell

I got an error.

I tried ‘do shell script’ alternatives but I could not ‘cd’ to the containing_folder. I could ‘ls’ the containing_folder but not cd to it to do a mv * … command.

The “Applescript” book by Rosenthal less that useless on this point and I scoured this forum to no result.

Finally I used a script that traveled all containing folders and moved all flies to the enclosing folder but it seems like a lot of firepower just for something as simple as “mv * …/”

So how do you get an instance of a folder, and its contents, if you don’t know the folders name before hand?

As always, thanks to all of you here who make scripting fun and an education… and make this forum THE resource for those of us who don’t know what the hell we are doing!

Hi,

You are very nearly there. This works for me:

tell application "Finder"
	set containing_folder to (choose folder)
	set enclosed_folder to first folder of containing_folder whose name contains "blueberry"
	move items of enclosed_folder to containing_folder
end tell

Best wishes

John M

You may want to look at Parent Folder or Spill Folders.

Thanks John!

I knew it should be easy… but I had no idea how close I was.

Any idea why 'do shell script "cd "& containing_folder doesn,t work?

Hello, I am macscripter’s unofficial TN2065 quoter. :wink:

Q: How can I use more than one command in a single do shell script? For example, I want to cd to some directory and then do some work, but it doesn’t remember the working directory from one invocation to the next.
A: Each invocation of do shell script uses a new shell process, so state such as changes to variables and the working directory is not saved from one to the next. To do several commands in a single invocation, separate the commands with semicolons like this:

do shell script "cd ~/Documents; ls"
-- result: "Welcome.txt"

Using a line feed (ASCII character 10) also works.