kaioker2
kaioker2

Reputation: 329

Scan for a file

I am new to applescript and am tying to automate a project i am working on. I will not load the code because it is 4 miles long (there is probably a more efficient way) but the general sense is something along the lines of:

if directory ~/Library/Application' 'Support/kaiotemp exists then
  do code 1
else 
  do code 2
end

I have tried my hardest but cant even come up with a base model that doesn't crash. Any ideas?

Upvotes: 0

Views: 117

Answers (1)

regulus6633
regulus6633

Reputation: 19032

The application Finder knows how to determine if a file or folder exists. Try this...

set folderPath to (path to home folder as text) & "Library:Application Support:kaiotemp:"

set folderExists to false
tell application "Finder"
    if folder folderPath exists then set folderExists to true
end tell

if folderExists then
    --do code 1
else
    --do code 2
end if

Notice my path versus your path. Applescript uses colon ":" delimited paths and the path starts with the name of your hard drive (I used the "path to" command to find the path to your home folder directly in this case). So you will need to take that into account if you have other paths in your code. You'll have to study how to convert posix paths to applescript paths.

Upvotes: 1

Related Questions