ChangeDir not working in Loop properly?

Blitz3D Forums/Blitz3D Programming/ChangeDir not working in Loop properly?

Guy Fawkes(Posted 2016) [#1]
EDIT: Double post.. Sorry about that...

~GF


Guy Fawkes(Posted 2016) [#2]
EDIT: I spoke a little too soon.. I can only make it change OUTSIDE the main loop. How do I make it changedir INSIDE of a loop?

ChangeDirTest1.bb:



Thanks for any help & support!

~GF


Matty(Posted 2016) [#3]
Whether it is in a loop or not will not change the way the changedir statement executes. I would say without looking too closely there is an error in your logic.


Floyd(Posted 2016) [#4]
ChangeDir will only work if the directory already exists. And the "\" does not belong at the front of the name.

ChangeDir "Data2"

or

ChangeDir "Data2\"

will change the directory provided Data2 exists in the current directory.

You can also use a fully qualified path like

ChangeDir "C:\Program Files (x86)\Blitz3D"

assuming there is such a thing.


Guy Fawkes(Posted 2016) [#5]
Look. Alls I want to do is be able to switch the directory (assuming it exists), in a loop. I need to do this so I can switch between different directories for different types of file requesters. Such as "Save", "Save As", & "Open"...

This is what I have.

DirChange.bb:



Thanks guys!

~GF


Floyd(Posted 2016) [#6]
You may be confused about what "current directory" means. It is where you are now and a reference to a file/folder such as "dwarf" looks inside the current directory. Even if a change to "Data" worked then a later change to simply dwarf would be looking inside this new location.

For any other behavior you need a full path. Note CurrentDir() is such a full path, not just a directory name.

Also note your Change_Dir blindly attempts a change and returns a value based on what you hoped would happen, not what actually occurred.

I would suggest you need a variable such as MasterPath$ to hold the location of all the directories you want to change to. It might have a value of the form

MasterPath$ = "C:\ThePathLeadingToMyFolder\MyFolder\"

Inside that would be other directories such as Data and dwarf. Then you could

ChangeDir MasterPath + "Data" or
ChangeDir MasterPath + "dwarf"

After this use CurrentDir() to see of the change succeeded.


Guy Fawkes(Posted 2016) [#7]
Thanks ALOT, Floyd! That worked out GREAT!



Enjoy!

~GF


Guy Fawkes(Posted 2016) [#8]
Here's a fix, and a funny quote. :P



~GF


RemiD(Posted 2016) [#9]
@GF>>What is your intent with this ? To scan a directory and to list the childs directories/files ?


Guy Fawkes(Posted 2016) [#10]
No. That was a test. To be able to use FileRequester to actually change to the correct directory.

~GF