Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Folder or File

Author
Message
Code eater
18
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 5th Jan 2009 18:47
hey,,,

I am writing a file viewer like thing, similar to those in say, Microsoft Word when you click 'Open'. But it obviously shows folders as well, so i need a way to destinguish between a file and a folder. But annoyingly folders can have dots(.) in them as well so that doesn't work. Is there any way to tell, from the name, whether or not it is a file or a folder.

thanks,,,

codeeater.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 5th Jan 2009 19:58
Hello Code eater!

I have written something like this, and here is the subroutine that scans the directory:



What you do, is you check first if the current file being scanned is a file with "if file exist()". If so, then it is a file, and you have to jump over the "if path exist" so it doesn`t change to a directory.

What I am saying is, that the "if file exist()" will equal 1 if it is a file, but the "if path exist()" will also equal 1, no matter what. So, if it is not a file, then it is a directory (check it anyway with "if path exist()" to be REALLY sure...).

TheComet

Peachy, and the Chaos of the Gems

BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 5th Jan 2009 20:07
This command is what you need:

Get File Type()

This will return (I believe) a 1 if the selected file is a folder, a 0 if it is a file and a -1 if there are no more files in the directory.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Code eater
18
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 6th Jan 2009 12:29
hey,,,

@TheComet

Thats awsome. Thanks.

@BN2
Thanks, but for that I need to keep using the Find Next() and Find First commands, which I don't really like and are a bit of a hassle. Thanks.


cheers,,,

codeeater
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 6th Jan 2009 16:55
Quote: "@BN2
Thanks, but for that I need to keep using the Find Next() and Find First commands, which I don't really like and are a bit of a hassle. Thanks."


Be careful using the Checklist commands. There actually is a limit to how many items are returned. NanogamezGuy spotted the problem during a DBC challenge I think. I think somewhere either in the counts or actual strings returned, the limit is 255 or 512 when using the Perform checklist for whatever. Using Find First and Fint Next eliminates that problem.

Enjoy your day.
BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 6th Jan 2009 17:55
Using the find first and find next commands also give access to extra commands, such as get file type and get file date. Like latch said, though, the major benefit to using it is that you don't have to worry about limits.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Code eater
18
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 10th Jan 2009 12:36
Oh ok. thanks.

When I'm using the file browser and I select drive y: (A network drive) it works, but when i select a folder in that drive it says that the path doesn't exist. But before making it go to that path, I use the "Path exist()" command.

It's a bit weird. Any clues why?

thanks,,

Codeeater
BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 10th Jan 2009 17:35
I ran into that problem a while back on the furious file scanner challenge in the DBC challenge thread. I think what you have to do is check if the path exists and then verify that it is a folder (using find next until you hit the right folder then use get file type)>

Try that out, I think I have a "Folder Exist" function somewhere, I will try to dig it up for you.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose

Login to post a reply

Server time is: 2026-07-05 01:47:58
Your offset time is: 2026-07-05 01:47:58