• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSFileManager's odd behavior
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSFileManager's odd behavior


  • Subject: Re: NSFileManager's odd behavior
  • From: Takaaki Naganoya <email@hidden>
  • Date: Wed, 22 Jul 2015 23:10:13 +0900

Thank you, Shane. It works! (It was wrong with me :-)

By the way…there is other odd behavior for me. It is the *speed*.

I thought AS2 is faster than AS1. But in fact, AS1 is about two times faster than AS2.

AS1: 2.793974995613 sec. (MacBook Pro Retina 2012, Core i7 2.6GHz)
AS2: 4.426485955715 sec. (MacBook Pro Retina 2012, Core i7 2.6GHz)



<AS1>
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"


set a1Dat to current application's NSDate's timeIntervalSinceReferenceDate()

repeat with i from 1 to 10000
	set aDirStr to "Desktop/test/" & (i as string)
	set aRes to makeDirUnderHome(aDirStr) of me
end repeat

set b1Dat to current application's NSDate's timeIntervalSinceReferenceDate()
set c1Dat to b1Dat - a1Dat
--> 2.793974995613 (MacBook Pro Retina 2012, Core i7 2.6GHz)


on makeDirUnderHome(dirStr)

	set homeDir to current application's NSHomeDirectory()
	set dirPath to homeDir's stringByAppendingPathComponent:dirStr
	set fileManager to current application's NSFileManager's defaultManager()


	--Sample with continuation mark (¬) , similar to Objective-C format
	set aRes to fileManager's createDirectoryAtPath:dirPath ¬
		withIntermediateDirectories:true ¬
		attributes:(missing value) ¬
		|error|:(reference)

	copy aRes to {aFlag, aError}
	return aFlag as boolean

end makeDirUnderHome
</AS1>


<AS2>

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set a1Dat to current application's NSDate's timeIntervalSinceReferenceDate()

set homeDir to current application's NSHomeDirectory()
set fileManager to current application's NSFileManager's defaultManager()


repeat with i from 1 to 10000

	set aDirText to "Desktop/test/" & (i as string)

	set aDirStr to (current application's NSString's stringWithString:aDirText)
	set dirPath to (homeDir's stringByAppendingPathComponent:aDirStr)

	set aRes to (fileManager's createDirectoryAtPath:dirPath withIntermediateDirectories:true attributes:(missing value) |error|:(reference))

end repeat

set b1Dat to current application's NSDate's timeIntervalSinceReferenceDate()
set c1Dat to b1Dat - a1Dat
--> 4.426485955715  (MacBook Pro Retina 2012, Core i7 2.6GHz)

</AS2>

> 2015/07/22 20:23、Shane Stanley <email@hidden> のメール:
>
> On 22 Jul 2015, at 9:09 pm, Takaaki Naganoya <email@hidden> wrote:
>>
>> This script generates 1000 folders on Desktop/test by using Cocoa NSFileManager.
>> But this stops after few folder generated. Why?
>
>> <snip>
>
>> 	set aRes to (fileManager's createDirectoryAtPath:dirPath withIntermediateDirectories:true attributes:false |error|:(reference))
>
> The problem is the attributes parameter. The documentation says it should be either a dictionary of attributes, or nil. Change that false to (missing value).
>
>> 	-->	error number -10000  -[__NSCFBoolean objectForKey:]: unrecognized selector sent to instance 0x7fff740798b8
>
> I suspect that __NSCFBoolean is your false argument; objectForKey: is a dictionary method, hence the exception.
>
> --
> Shane Stanley <email@hidden>
> <www.macosxautomation.com/applescript/apps/>
>
>
> _______________________________________________
> 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

--
Takaaki Naganoya
email@hidden
http://piyocast.com/as/




 _______________________________________________
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


  • Follow-Ups:
    • Re: NSFileManager's odd behavior
      • From: Shane Stanley <email@hidden>
    • Re: NSFileManager's odd behavior
      • From: Axel Luttgens <email@hidden>
References: 
 >NSFileManager's odd behavior (From: Takaaki Naganoya <email@hidden>)
 >Re: NSFileManager's odd behavior (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: NSFileManager's odd behavior
  • Next by Date: Re: NSFileManager's odd behavior
  • Previous by thread: Re: NSFileManager's odd behavior
  • Next by thread: Re: NSFileManager's odd behavior
  • Index(es):
    • Date
    • Thread