Re: Making up a file name
Re: Making up a file name
- Subject: Re: Making up a file name
- From: Yvan KOENIG <email@hidden>
- Date: Thu, 09 Mar 2017 15:55:44 +0100
Le 9 mars 2017 à 12:57, Jan Erik Moström < email@hidden> a écrit :
Hi,
It has been many years since I wrote an applescript longer than 2 lines so be kind.
I want to create a file and I want it to have the name "todays date + random text string", i.e. something like this "2017-03-09-svnszfvjsckvtte"
After looking at the web I wrote the code below. The problem is that the existFile function always return true, no matter if the file actually exists or not.
I assume I'm missing something really basic but I can't figure out what?
on makeFileName(todaysDate, basePath) set fn to "" repeat 15 times set fn to fn & (character id (random number from 97 to 122)) end repeat return POSIX file (basePath & (the short date string of todaysDate) & "-" & fn) end makeFileName
on existFile(fp) log fp as text tell application "System Events" return exists fp end tell end existFile
set td to (current date) set destFile to makeFileName(td, "/Users/jem/Desktop/")
existFile(destFile)
Your code is not checking that there is an item on the disk, it checks that you have created a descriptor of a file. Edit the code this way :on existFile(fp) log fp as text tell application "System Events" return exists disk item (fp as text) # EDITED end tell end existFile
Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) jeudi 9 mars 2017 15:55:38
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden