How to: Change working directory

Just starting out? Need help? Post your questions and find answers here.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

How to: Change working directory

Post 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:
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: How to: Change working directory

Post by ts-soft »

Code: Select all

SetCurrentDirectory()
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: How to: Change working directory

Post 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:
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: How to: Change working directory

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: How to: Change working directory

Post 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
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: How to: Change working directory

Post 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
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: How to: Change working directory

Post 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.
infratec
Always Here
Always Here
Posts: 7591
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to: Change working directory

Post 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
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: How to: Change working directory

Post 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:
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: How to: Change working directory

Post 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)....
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Post Reply