GLBasic forum

Main forum => GLBasic - en => Topic started by: bigtunacan on 2013-Nov-24

Title: File or Directory?
Post by: bigtunacan on 2013-Nov-24
Is there a way to test for the difference between a file or directory?

I have tried the following two functions, but both return true for files and directories...

Code (glbasic) Select

DOESDIREXIST
DOESFILEEXIST
Title: Re: File or Directory?
Post by: mentalthink on 2013-Nov-24
Code (glbasic) Select
Hi Bugtunacan, take a look to this code, you can find in the help searching GETFILELIST() command
With the Orange part I think you have enough for your Code.

// --------------------------------- //
// Project: Files and Folders
// Start: Tuesday, November 25, 2003
// IDE Version: 1.31125

LOADFONT "minifont.bmp", 0
GETFONTSIZE font_x, font_y

[color=orange] ok = SETCURRENTDIR("..") // One up
cur$ = GETCURRENTDIR$()
num = GETFILELIST("*.*", files$[])
num_dir  = INTEGER(num / 0x10000) // Hi-Word
num_file = MOD(num, 0x10000)      // Lo-Word
[/color]
PRINT cur$, 0, 0
PRINT "ok? " + ok+ " num: " + num + " -> nDir: "+num_dir+" nFile: "+num_file, 0, font_y
FOR i=0 TO BOUNDS(files$[], 0)-1 // BOUNDS(files$[], 0)-1 = num = num_dir+num_file
  PRINT files$[i], 0, (i+3)*font_y
NEXT

SHOWSCREEN
MOUSEWAIT

Title: Re: File or Directory?
Post by: spacefractal on 2013-Nov-24
Do you uses the newest glbasic? Else this might been a strange bug, which should not been happens.

Alternative, you could test the file by trying to open the file, if its exists.If you cant open the file, then its would been a directory....
Title: Re: File or Directory?
Post by: Kitty Hello on 2013-Nov-24
If it's true, its a bug. What platform?
Title: Re: File or Directory?
Post by: Moru on 2013-Nov-24
Windows 7 works for me at least, here is my testcode:

Code (glbasic) Select
LOCAL ok%, file$

file$ = "C:/temp/"
ok% = DOESDIREXIST(file$)
IF ok% = TRUE
DEBUG "\n Is dir: " + file$
ELSE
DEBUG "\n No dir: " + file$
ENDIF
ok% = DOESFILEEXIST(file$)
IF ok% = TRUE
DEBUG "\n Is file: " + file$
ELSE
DEBUG "\n No file: " + file$
ENDIF


file$ = "C:/temp/test.txt"
ok% = DOESDIREXIST(file$)
IF ok% = TRUE
DEBUG "\n Is dir: " + file$
ELSE
DEBUG "\n No dir: " + file$
ENDIF
ok% = DOESFILEEXIST(file$)
IF ok% = TRUE
DEBUG "\n Is file: " + file$
ELSE
DEBUG "\n No file: " + file$
ENDIF


Code (glbasic) Select
Is dir:  C:/temp/
No file: C:/temp/
No dir:  C:/temp/test.txt
Is file: C:/temp/test.txt