iOS Question File.IsDirectory & File.MakeDir error

Gianni Sassanelli

Active Member
Licensed User
Longtime User
Hi
i get error when try this code and Dir not Exists

B4X:
File.IsDirectory(File.DirRootExternal , "MyApp") 
'or 
File.IsDirectory(File.DirRootExternal , "/MyApp")

how can i test if dir exist and create a dir?

tks
 

Star-Dust

Expert
Licensed User
Longtime User
DirRootExternal dont exit in iOS
 
Upvote 0

Gianni Sassanelli

Active Member
Licensed User
Longtime User
DirRootExternal dont exit in iOS
i'm confused
i want to write DirDocuments but i have always error
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Post log error
 
Upvote 0

Gianni Sassanelli

Active Member
Licensed User
Longtime User
B4X:
        myDir             = "TS_Storage"
        myResource         = "Images"
        Try
            If Not(File.IsDirectory(File.DirDocuments ,myDir)) Then 
                File.MakeDir(File.DirDocuments, myDir)  ' this line has error
            End If
        Catch
            File.MakeDir(File.DirDocuments, myDir)   ' with this line dir is created
        End Try    
        Msgbox(File.IsDirectory(File.DirDocuments,myDir),"Verifica esistenza Dir...")
        Try
            If Not(File.IsDirectory(File.DirDocuments ,File.Combine(myDir, myResource))) Then 
                File.MakeDir(File.DirDocuments, File.Combine(myDir, myResource))
            End If
        Catch
            File.MakeDir(File.DirDocuments, File.Combine(myDir, myResource))
        End Try    
        Msgbox(File.IsDirectory(File.DirDocuments,File.Combine(myDir, myResource)),"Verifica esistenza Dir...")

Error
Application_Start
Error occurred on line: 55 (ts_App)
Error getting attributes: Error Domain=NSCocoaErrorDomain Code=260 "The file “TS_Storage” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/techservice/Library/Developer/CoreSimulator/Devices/EBEA0EDA-452D-4408-9367-09DED1B2561F/data/Containers/Data/Application/0ACEF91C-266B-4593-B610-C46B487EEBFF/Documents/TS_Storage, NSUnderlyingError=0x6000018a9e60 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
Stack Trace: (
CoreFoundation __exceptionPreprocess + 350
libobjc.A.dylib objc_exception_throw + 48
CoreFoundation +[NSException raise:format:] + 188
Test 02 -[B4IFile GetAttributes::] + 388
Test 02 -[B4IFile IsDirectory::] + 98
CoreFoundation __invoking___ + 140
CoreFoundation -[NSInvocation invoke] + 321
Test 02 +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1650
Test 02 -[B4IShell runMethod:] + 380
Test 02 -[B4IShell raiseEventImpl:method:args::] + 1566
Test 02 -[B4IShellBI raiseEvent:event:params:] + 1358
Test 02 +[B4IDebug delegate:::] + 66
Test 02 -[b4i_ts_app _initialize::] + 390
Test 02 -[b4i_b4xmainpage _b4xpage_created::] + 743
CoreFoundation __invoking___ + 140
CoreFoundation -[NSInvocation invoke] + 321
Test 02 +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1650
Test 02 -[B4ICommon CallSubDebug4::::] + 1061
Test 02 -[B4ICommon CallSubDebug2::::] + 326
Test 02 -[b4i_b4xpagesmanager _createpageifneeded::] + 1183
Test 02 -[b4i_b4xpagesmanager _showpage::] + 780
Test 02 -[b4i_b4xpagesmanager _addpage:::] + 1464
Test 02 -[b4i_b4xpagesmanager _addpageandcreate:::] + 599
Test 02 -[b4i_b4xpagesmanager _initialize:::] + 1918
Test 02 -[b4i_main _application_start:] + 634
CoreFoundation __invoking___ + 140
CoreFoundation -[NSInvocation invoke] + 321
Test 02 +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1650
Test 02 -[B4IShell runMethod:] + 380
Test 02 -[B4IShell raiseEventImpl:method:args::] + 2076
Test 02 -[B4IShellBI raiseEvent:event:params:] + 1358
Test 02 __33-[B4I raiseUIEvent:event:params:]_block_invoke + 51
libdispatch.dylib _dispatch_call_block_and_release + 12
libdispatch.dylib _dispatch_client_callout + 8
libdispatch.dylib _dispatch_main_queue_callback_4CF + 1042
CoreFoundation __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
CoreFoundation __CFRunLoopRun + 2041
CoreFoundation CFRunLoopRunSpecific + 404
GraphicsServices GSEventRunModal + 139
UIKitCore UIApplicationMain + 1605
Test 02 main + 112
libdyld.dylib start + 1
??? 0x0 + 1
)
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I should test but right now I don't have iPhone with me. But I guess the problem is that before using isDirectory you have to use isExists

The error indicates that the file you want to check does not exist if it is a directory
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
B4X:
        myDir             = "TS_Storage"
        myResource         = "Images"
        Try
            If Not(File.IsDirectory(File.DirDocuments ,myDir)) Then
                File.MakeDir(File.DirDocuments, myDir)  ' this line has error
            End If
        Catch
            File.MakeDir(File.DirDocuments, myDir)   ' with this line dir is created
        End Try   
        Msgbox(File.IsDirectory(File.DirDocuments,myDir),"Verifica esistenza Dir...")
        Try
            If Not(File.IsDirectory(File.DirDocuments ,File.Combine(myDir, myResource))) Then
                File.MakeDir(File.DirDocuments, File.Combine(myDir, myResource))
            End If
        Catch
            File.MakeDir(File.DirDocuments, File.Combine(myDir, myResource))
        End Try   
        Msgbox(File.IsDirectory(File.DirDocuments,File.Combine(myDir, myResource)),"Verifica esistenza Dir...")

Error
Application_Start
Error occurred on line: 55 (ts_App)
Error getting attributes: Error Domain=NSCocoaErrorDomain Code=260 "The file “TS_Storage” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/techservice/Library/Developer/CoreSimulator/Devices/EBEA0EDA-452D-4408-9367-09DED1B2561F/data/Containers/Data/Application/0ACEF91C-266B-4593-B610-C46B487EEBFF/Documents/TS_Storage, NSUnderlyingError=0x6000018a9e60 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
Stack Trace: (
CoreFoundation __exceptionPreprocess + 350
libobjc.A.dylib objc_exception_throw + 48
CoreFoundation +[NSException raise:format:] + 188
Test 02 -[B4IFile GetAttributes::] + 388
Test 02 -[B4IFile IsDirectory::] + 98
CoreFoundation __invoking___ + 140
CoreFoundation -[NSInvocation invoke] + 321
Test 02 +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1650
Test 02 -[B4IShell runMethod:] + 380
Test 02 -[B4IShell raiseEventImpl:method:args::] + 1566
Test 02 -[B4IShellBI raiseEvent:event:params:] + 1358
Test 02 +[B4IDebug delegate:::] + 66
Test 02 -[b4i_ts_app _initialize::] + 390
Test 02 -[b4i_b4xmainpage _b4xpage_created::] + 743
CoreFoundation __invoking___ + 140
CoreFoundation -[NSInvocation invoke] + 321
Test 02 +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1650
Test 02 -[B4ICommon CallSubDebug4::::] + 1061
Test 02 -[B4ICommon CallSubDebug2::::] + 326
Test 02 -[b4i_b4xpagesmanager _createpageifneeded::] + 1183
Test 02 -[b4i_b4xpagesmanager _showpage::] + 780
Test 02 -[b4i_b4xpagesmanager _addpage:::] + 1464
Test 02 -[b4i_b4xpagesmanager _addpageandcreate:::] + 599
Test 02 -[b4i_b4xpagesmanager _initialize:::] + 1918
Test 02 -[b4i_main _application_start:] + 634
CoreFoundation __invoking___ + 140
CoreFoundation -[NSInvocation invoke] + 321
Test 02 +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1650
Test 02 -[B4IShell runMethod:] + 380
Test 02 -[B4IShell raiseEventImpl:method:args::] + 2076
Test 02 -[B4IShellBI raiseEvent:event:params:] + 1358
Test 02 __33-[B4I raiseUIEvent:event:params:]_block_invoke + 51
libdispatch.dylib _dispatch_call_block_and_release + 12
libdispatch.dylib _dispatch_client_callout + 8
libdispatch.dylib _dispatch_main_queue_callback_4CF + 1042
CoreFoundation __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
CoreFoundation __CFRunLoopRun + 2041
CoreFoundation CFRunLoopRunSpecific + 404
GraphicsServices GSEventRunModal + 139
UIKitCore UIApplicationMain + 1605
Test 02 main + 112
libdyld.dylib start + 1
??? 0x0 + 1
)

the reason for the error is you check if myDir is a directory or not but you are not checking if it exists.
the same error should be happening in b4a if the folder does not exist. if you don't get it in b4a it is because it exists for some reason.
 
Upvote 0
Top