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 / Going Back a Directory

Author
Message
D a r k
19
Years of Service
User Offline
Joined: 21st Jun 2004
Location: In ur fridge, eatin ur foodz.
Posted: 17th Aug 2005 04:18
Okay I need to know what command I use to go back a directory.

For Example

The main code is in the "Game" folder.
After that I use the command CD "User_Interface" to load the images. Now how do I get back to the "Game" folder= from the "User_Interface" folder.

The "User_Interface" folder is inside the "Game" folder.
Me!
18
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 17th Aug 2005 11:13
cd ".."

note the two dots, it means go up one level in DOS, example code



Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 17th Aug 2005 17:32 Edited at: 17th Aug 2005 17:32
Your directory may not exceed a specified length. (I think it's 255 chars). And I thought using that just ads "\.." to your current directory. I used this:



Immunity and Annihalation makes Immunihalation...
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 17th Aug 2005 17:40 Edited at: 18th Aug 2005 03:07
I use Get Dir$() too, but at the start of the program, set up strings containing all the paths I will need in the program. For example:

StartDir$ = Get Dir$()
ImageDir$ = StartDir$+"\Images"
SaveGameDir$ = StartDir$+"\SaveGames"

and so on for each sub-directory you need.

CD ImageDir$ will switch to the Images sub-directory and when finished, CD StartDir$ will switch back to the directory the program is in.

TDK_Man

Me!
18
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 17th Aug 2005 17:45
:Sven B

, all that "set dir get dir$() + "\.."" does is set the directory to the current directory + "..", CD works relative to the current directory and so CD ".." is exactly the same as "set dir get dir$() + "\.."" but minus the extra typing , you might be thinking of cd ".", which moves you to the directory you are in (don`t ask me why...ask Micro$oft)

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 17th Aug 2005 21:03
That's not what I meant.
Let's say you are in this dir:
"C:\program files\DarkBasic Software\DarkBasic"

and you go to the parent folder. So + "\.."

"C:\program files\DarkBasic Software\DarkBasic\.."

and again:

"C:\program files\DarkBasic Software\DarkBasic\..\.."

etc...

The directory will ultimately exceed the ?255? character length and give an error. That's why I would use this:

"C:\program files\DarkBasic Software\DarkBasic"

go back:

"C:\program files\DarkBasic Software\DarkBasic\.."

get dir$():

"C:\program files\DarkBasic Software"

And the length of your directory is smaller again.

Immunity and Annihalation makes Immunihalation...
Me!
18
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 17th Aug 2005 22:32 Edited at: 17th Aug 2005 22:37
it doesn`t get longer, all it does is set the current directory 1 further up the tree, if you are in deep enough you can do a million cd ".."'s, you don`t add it to the path, it works from where you are automaticaly, you can either enter another folder from the directory you are in, eg

cd "anotherfolder"

or you can go back to the parent folder with dot dot..eg

cd ".."

while going deeper into folders will eventualy go beyond what the filesytem can handle, doing ".." will just make the path shorter, trust me, at one time DOS was the only way to talk to `puters, I lived through it, .. doesn`t make the path longer, it removes the last dir in the path, if you have the path

c:\folder1\folder2\folder3\folder4

then cd ".."

makes the path into

C:\folder1\folder2\folder3

NOT

c:\folder1\folder2\folder3\folder4\..\

the second says

go to drive c, go to folder1 got to folder2 in folder 1, got to folder3 in folder2, now go to folder4 in folder 3, now go back to folder 3, if you check your directory with get dir$ you get the shortened path (see the original example), not a path with ".." appended.



edited to correct the dreaded forum backslash eating bug
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 18th Aug 2005 03:09
All of which goes to prove that my idea is a pretty good one for when your programs need to temporarily switch from one directory to another right?

Well?...

Come on guys back me up!

TDK_Man

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 18th Aug 2005 13:31
It's just the way I worked. I didn't use "cd". This is what I did:

if file type() = 1
currentdir$ = currentdir$ + "\" + get file name$()
set dir currentdir$
endif

So in my code it DOES gain length each time I go back a folder.

So I solved it my way:

if file type() = 1
currentdir$ = currentdir$ + "\" + get file name$()
set dir currentdir$
currentdir$ = get dir$()
set dir currentdir$
perform checklist for files
endif

Immunity and Annihalation makes Immunihalation...
Me!
18
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 18th Aug 2005 15:22 Edited at: 18th Aug 2005 15:24
as always, theres hundreds of ways to code the same thing and no one way is the right way, I just didn`t want anyone thinking they had to add checks to make sure the path didn`t get too large and ending up with humungus wodge of code that would take a week to read for no good reason, either way does the job fine.
TDK`s way is the more structured as long as you know what folders and files you will be looking at, only downside is that if you allow a user to define their own save folders or whatever, then you have no way to predefine the location, but it`s good for the more traditional games, less prone to tryping erors tu.

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 18th Aug 2005 19:17
Why doing it easy when it can be done hard...

(That's me)

Immunity and Annihalation makes Immunihalation...
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Aug 2005 00:35
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Aug 2005 04:10
Quote: "Why doing it easy when it can be done hard..."


Only do things the hard way till you discover the easy way.

Login to post a reply

Server time is: 2024-04-20 02:37:33
Your offset time is: 2024-04-20 02:37:33