Page 1 of 1

How to: Change working directory

Posted: Sat Jan 02, 2010 9:29 pm
by charvista
How do I change the current working directory ?

MKDIR ==> Result = CreateDirectory(DirectoryName$)
RMDIR ==> Result = DeleteDirectory(DirectoryName$, Pattern$ [, Mode])
REN ==> Result = RenameFile(OldFilename$, NewFilename$) ; Its even possible to rename directory names, just use the related path with directory name
CHDIR ==> ???

It is NOT:
ChangeDirectory()... UseDirectory()... SetDirectory()... WorkingDirectory()... SwitchDirectory()... :cry: Couldn't imagine other possible words :roll:

Re: How to: Change working directory

Posted: Sat Jan 02, 2010 9:30 pm
by ts-soft

Code: Select all

SetCurrentDirectory()

Re: How to: Change working directory

Posted: Sat Jan 02, 2010 9:37 pm
by charvista
Thanks Thomas !
It's obvious of course... Maybe it could be easier if the terms were all reversed, like DirectoryCreate, DirectoryDelete, etc... but then PB has to be completely rewritten !! This of course not possible, so I will (hopefully) remember ! :wink:

Re: How to: Change working directory

Posted: Sat Jan 02, 2010 9:59 pm
by IdeasVacuum
charvista wrote:Maybe it could be easier if the terms were all reversed, like DirectoryCreate, DirectoryDelete, etc... :wink:
That syntax would be better because it is more logical. As you have said, it would hurt too many existing programs if PB were to change now, but for your own purposes it is possible to write a .pb file using macros to define the syntax to your preference. You would simply then include that code in each project.

Re: How to: Change working directory

Posted: Sat Jan 02, 2010 11:04 pm
by charvista
@IdeasVacuum
As you said it so well in your signature, I will keep it simple, and try to remember the terms created by the PureBasic Team.
But there is something "worse" than that.
Some commands, like to move a window or a gadget, you should'nt search near the Move term, because it's ResizeWindow() and ResizeGadget()! I wasted once some hours finding it, and had to ask the forum... I'm sure many others had the same problem. I believe MoveWindow() once existed before, but the PB-Team removed it (a pity, but they must have their reasons).
If you want to disable a gadget, you will use DisableGadget(). So far, no problem. But how will you re-enable it? Logigally, you will search the Help file for EnableGadget()... Well no, that does not exists... Because.... it is DisableGadget() too! Of course with State 0. Ambiguous, isn't it? Hilarous to say that, if you want to show a gadget, you must use HideGadget() :mrgreen:
When a programmer is writing a program, he/she is re-reading it many times. Then it must be very clear, with appropriate, self-explaining terms. For this reason, I have written procedures (not macros) MoveGadget() and EnableGadget() to avoid confusion.....

Code: Select all

Procedure.i MoveWindow(WinNo, x, y, Width, Height)
    R.i = ResizeWindow(WinNo, x, y, Width, Height)
    ProcedureReturn R
EndProcedure

Procedure.i MoveGadget(GadNo, x, y, Width, Height)
    R.i = ResizeGadget(GadNo, x, y, Width, Height)
    ProcedureReturn R
EndProcedure

Procedure.i EnableGadget(GadNo)
    R.i = DisableGadget(GadNo, 0)
    ProcedureReturn R
EndProcedure
    
Procedure.i EnableWindow(WinNo)
    R.i = DisableGadget(WinNo, 0)
    ProcedureReturn R
EndProcedure
Sorry for going off-topic....
Richard

Re: How to: Change working directory

Posted: Sat Jan 02, 2010 11:21 pm
by charvista
This is very funny :P

Code: Select all

Procedure.i MoveWindow(WinNo, x, y, Width, Height)
    R.i = ResizeWindow(WinNo, x, y, Width, Height)
    ProcedureReturn R
EndProcedure

OpenWindow(0,20,20,400,400,"Try to touch me...")

Repeat
    EventID = WaitWindowEvent()
        Select EventID
            Case 512 ; meaning that the mouse has moved (even for just 1 pixel)
                MoveWindow(0, Random(500), Random(500), 400, 400)
            Case #PB_Event_CloseWindow
                Quit = 1
        EndSelect
Until Quit = 1
End

Re: How to: Change working directory

Posted: Sun Jan 03, 2010 1:25 pm
by Fred
Reversed terms are not human readable (unless you live in Starwars movie :P). The goal is to read the statements like you would do with a book:

Code: Select all

If CreateDirectory("Test")
EndIf
Having reversed looks wierd:

Code: Select all

If DirectoryCreate("Test")
EndIf
May be a matter of taste.

About the functions which does 2 actions in one, it's to limit the commandsets. If you had 10.000 functions to search on, you would be even more lost. BTW, the win32 API adopts the same scheme: you don't have DisableWindow(), but only an EnableWindow() etc.

Re: How to: Change working directory

Posted: Sun Jan 03, 2010 2:09 pm
by infratec
@charvista

why do think minutes above some possible names :?: :?: :?:

If you find the help for CreateDirectory(), simply go to the bottom of the help
and click on the FileSystem index.
Than scroll down and read the available commands.
SetCurrentDirectory() is listed there.

Bernd

Re: How to: Change working directory

Posted: Sun Jan 03, 2010 2:57 pm
by charvista
@Fred
I certainly live in a Star Trek movie :P and thinking like Mr. Spock or Mr. Data with computers is very natural :roll:
The idea always starts with the biggest thing, then going to the finest detail. A good example is our Date system in the Sino-Japanese system (or the StarDate :P ) where they start with the year first, then month, then date, then hour, then minute, then seconds.... and not like the European DD/MM/YYYY or like the American MM/DD/YYYY. With the Japanese (and computer) method all dates are automatically sorted (20091231 is smaller than 20100101, but 31122009 (or 12312009) is larger than 01012010).
Grouping keywords is not a so bad idea, for example, all commands related to the printer may begin with Printer:
PrinterRequester, PrinterOpen, PrinterClose, PrinterOrientation, PrinterNumberOfCopies, etcaetera..... It's logical, fast to find, easier to remember and more professional.
It's already "strange" that you have PrintRequester and not RequestPrinter... hehe :wink:

@Bernd (infratec)
Yes, I could and should have to. But my brain was beamed up and not down :mrgreen:

Re: How to: Change working directory

Posted: Sun Jan 03, 2010 3:07 pm
by charvista
About the functions which does 2 actions in one, it's to limit the commandsets. If you had 10.000 functions to search on, you would be even more lost. BTW, the win32 API adopts the same scheme: you don't have DisableWindow(), but only an EnableWindow() etc.
Hmmm... Of course that's Microsoft's way of thinking. But it's not necessary to imitate them. Firstly, I would have called them WindowEnable() and WindowDisable(), and secondly, when grouping commands to reduce the number of functions, I would have simply called it Window() with an action as parameter, eg. Window(#Enable) and Window(#Disable)....