Error in Creation of Directory

mkvidyashankar

Active Member
Licensed User
Longtime User
I am trying to check for Directory, if not exist to create directory using this code
but no able to create the directory, even if it is not existed

B4X:
 ' create directory--------------------------------------------------
   If File.ExternalWritable=True Then
      If File.IsDirectory(File.DirRootExternal,"vidnews/") = False Then
                File.MakeDir(File.DirRootExternal,"vidnews/")
        End If
      filedire=File.DirRootExternal & "/vidnews"
       
   Else
      If File.IsDirectory(File.DirInternal,"vidnews/")= False Then
            File.MakeDir(File.DirInternal,"vidnews/")
      End If
      filedire="File.DirInternal"
   End If
   
   '-------------------------------------------------------------------

where i am erring?
 

mkvidyashankar

Active Member
Licensed User
Longtime User
I tried but getting the same problem

log is here


main_buttontopage_click (B4A line: 877)
filelist=File.ListFiles(filedire)
java.io.IOException: /mnt/sdcard/vidnews is not a folder.
at anywheresoftware.b4a.objects.streams.File.ListFiles(File.java:154)
at com.ausnews.main._buttontopage_click(main.java:1405)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:158)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:54)
at android.view.View.performClick(View.java:2538)
at android.view.View$PerformClick.run(View.java:9152)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
java.io.IOException: /mnt/sdcard/vidnews is not a folder.
 
Upvote 0

mkvidyashankar

Active Member
Licensed User
Longtime User
Here is the code

Problem is creating the directory.

B4X:
Sub Activity_Create(FirstTime As Boolean)

   Dim server As ServerSocket 'Add a reference to the network library
    server.Initialize(0, "")
    If server.GetMyIP = "127.0.0.1" Then  'this is the local host address
       ToastMessageShow( "This Device is not connected to the internet. Please Connect the Device to the internet before using this app !!!!!",True)
      Return 
   End If
   ' create directory--------------------------------------------------
    If File.ExternalWritable Then
        File.MakeDir(File.DirRootExternal, "vidnews")
        filedire = File.DirRootExternal & "/vidnews"
    Else
        File.MakeDir(File.DirInternal, "vidnews")
        filedire = File.DirInternal & "/vidnews"
    End If
   
   
'   If File.ExternalWritable Then
'      If File.IsDirectory(File.DirRootExternal,"vidnews/") = False Then
'                File.MakeDir(File.DirRootExternal,"vidnews/")
'        End If
'      filedire=File.DirRootExternal & "/vidnews"
'       
'   Else
'      If File.IsDirectory(File.DirInternal,"vidnews/")= False Then
'            File.MakeDir(File.DirInternal,"vidnews/")
'      End If
'      filedire="File.DirInternal"
'   End If
   
   '-------------------------------------------------------------------
    If FirstTime Then
        gps1.Initialize("GPS")
      Httpclient1.Initialize("HttpClient1")
      Parser.Initialize
      hc.Initialize("hc")
      mfor.Initialize("mfor")
   End If
      timer3.Initialize("timer3",900000)
      timerad.Initialize("timerad",30000)
      timerad.Enabled=True
      gps1.Start(50000,0)
    
   Activity.AddMenuItem2("Back", "mnuBack",LoadBitmap(File.DirAssets,"back.png"))
   Activity.AddMenuItem2("Forward", "mnuForward",LoadBitmap(File.DirAssets,"forward.png"))
  
End sub




--------------------------------------------
Sub ButtonTOpage_Click
     Dim j As Int
   Dim txt1,txt2 As String
   masterpanel.Visible=False
   childpanel.Visible=True
   filelistview.Clear
   filelist=File.ListFiles(filedire)
   For j= 0 To filelist.Size-1 
           txt1=filelist.Get(j)
         DateTime.DateFormat="dd-MMM-yyyy hh:mm:ss"
         txt2="Saved on :" & DateTime.Date(File.LastModified(filedire,filelist.Get(j)))
          filelistview.AddTwoLines(txt1,txt2)
   Next
   adview1.LoadAd
   'adLeadbolt.loadLeadboltAds("746835265", adLeadbolt.ADS_APP)
   If filelist.Size= 0 Then ToastMessageShow("You have not saved any pages !",True)
End Sub
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
just a thought. check your sd card for a file named vidnews. perhaps, earlier attempts of you yo create a directory, ended up with the creation of a file instead. if you find such a file (not directory), delete it and check again if you receive the same error.
 
Upvote 0

mkvidyashankar

Active Member
Licensed User
Longtime User
just a thought. check your sd card for a file named vidnews. perhaps, earlier attempts of you yo create a directory, ended up with the creation of a file instead. if you find such a file (not directory), delete it and check again if you receive the same error.

Thanks for the reply. I checked the directory, no such file is found. the same code is working in other app. so totally confused.:confused:
 
Upvote 0
Top