I am looking if the folder “FPAQ” and if the subfolder VideoFile" exist within the home user directory.
I do have a problem with the second if statement. It seems that the returned value is an integer when it should be a string.
Does what I am trying to make sense?
Regards!
Daniel
the structure is “MacIntosh HD:Users:FPAQ:Videofile:”
tell application "Finder"
set HomeFolder to (path to home folder as text)
set pathFolder1 to "FPAQ:" as string
if (exists folder pathFolder1 of folder HomeFolder) is true then
display dialog "Folder : " & pathFolder1 & " exist"
set pathFolder2 to "VideoFile:" as string
if (exists (folder pathFolder2) of folder pathFolder1 of HomeFolder) is true then
display dialog "Folder : " & pathFolder2 & " exist"
end if
else
make new folder at HomeFolder with properties {name:pathFolder1}
make new folder at folder pathFolder1 of HomeFolder with properties {name:pathFolder2}
end if
end Tell
Hi,
you don’t need to add “is true” after an exists command, try this.
tell application "Finder"
set pathFolder1 to "FPAQ"
if (exists folder pathFolder1 of home) then
display dialog "Folder : " & pathFolder1 & " exist"
set pathFolder2 to "VideoFile"
if exists (folder pathFolder2 of folder pathFolder1 of home) then
display dialog "Folder : " & pathFolder2 & " exist"
else
make new folder at folder pathFolder1 of home with properties {name:pathFolder2}
end if
else
set FPAQFolder to make new folder at home with properties {name:pathFolder1}
make new folder at FPAQFolder with properties {name:pathFolder2}
end if
end tell
Note: The Finder has a property home, which points to the home folder of the current user
You can do the same thing with one shell script line
do shell script "mkdir -p " & quoted form of (POSIX path of (path to home folder) & "FPAQ/VideoFile")
The folder(s) will only be created, if they don’t exist
try this…
set HomeFolder to (path to home folder as text)
set pathFolder1Name to "FPAQ"
set pathFolder2Name to "VideoFile"
tell application "Finder"
if not (exists folder (HomeFolder & pathFolder1Name)) then
make new folder at folder HomeFolder with properties {name:pathFolder1Name}
else
display dialog "Folder : " & pathFolder1Name & " exist"
end if
if not (exists folder (HomeFolder & pathFolder1Name & ":" & pathFolder2Name)) then
make new folder at folder (HomeFolder & pathFolder1Name) with properties {name:pathFolder2Name}
else
display dialog "Folder : " & pathFolder2Name & " exist"
end if
end tell