BBC BASIC for Windows
« pwd equivalent? »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:15pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: pwd equivalent?  (Read 888 times)
g3nrw
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 74
xx pwd equivalent?
« Thread started on: Sep 21st, 2013, 4:57pm »

I want to dynamically discover the current Windows folder at runtime. Is there a way to do this?

--
73
Ian, G3NRW

User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: pwd equivalent?
« Reply #1 on: Sep 21st, 2013, 5:58pm »

on Sep 21st, 2013, 4:57pm, g3nrw wrote:
I want to dynamically discover the current Windows folder at runtime. Is there a way to do this?

The first thing to note is that the 'current directory' won't change unless you change it, since it's private to each process, so you can keep track of any changes you make yourself. Having said that, there's very rarely any need to change it:

http://bb4w.wikispaces.com/When+and+when+not+to+use+%2ACD

But if you simply want to know what it is you can call the 'GetCurrentDirectory' API:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa364934.aspx

A BBC BASIC function FNcurrentdirectory to do that is listed in the Help manual under 'Operating System Interface... *CHDIR':

http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin8.html#chdir

Richard.
User IP Logged

g3nrw
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 74
xx Re: pwd equivalent?
« Reply #2 on: Sep 22nd, 2013, 08:53am »

Many thanks Richard. I discovered the links you mentioned soon after I posted -- there is so *much* excellent documentation to plough through!

Now another, even simpler, question to do with directories. I want to dynamically create a subfolder, called (for example) sub1, sub2, sub3, subn etc.

I have tried something like:

~~~~~~~~~~~~~~~~~~~~~
subfolder_name$ = "sub1"
*MKDIR subfolder_name$
~~~~~~~~~~~~~~~~~~~~~

but that just creates a folder called literally "subfolder_name$". Is there any way to express the name as a variable when using*MKDIR?

Another simple question: if the folder already exists, I get the "File exists" message. How can I trap (and ignore) this?

Sorry for the very basic questions. I really have dug through all the documentation I can find, and spent a long (interesting) time experimenting!

--
73
Ian, G3NRW





User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: pwd equivalent?
« Reply #3 on: Sep 22nd, 2013, 10:01am »

on Sep 22nd, 2013, 08:53am, g3nrw wrote:
I have tried something like:

Code:
subfolder_name$ = "sub1"
*MKDIR subfolder_name$ 

See the Help file under 'Operating system interface... Accessing star commands':

http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin8.html#accessing

There it says "OSCLI must be used when all or part of the star command needs to be determined at run-time (i.e. is a variable rather than a constant)".

In the section on MKDIR there is code listed specifically to do what you want:

Code:
OSCLI "MKDIR """+directory$+"""" 

Quote:
Another simple question: if the folder already exists, I get the "File exists" message. How can I trap (and ignore) this?

You basically have three options:
  1. Test whether the directory exists first. You can easily do that by attempting to open the virtual file NUL which exists in every directory:
    Code:
      exists% = OPENIN(directory$ + "\NUL")
      IF exists% CLOSE #exists% ELSE OSCLI "MKDIR """+directory$+"""" 

  2. Wrap the MKDIR call in a procedure and trap errors locally:
    Code:
      DEF PROCmkdir(directory$)
      ON ERROR LOCAL ENDPROC
      OSCLI "MKDIR """+directory$+""""
      ENDPROC 

  3. Use the Windows API, and ignore the returned value:
    Code:
      SYS "CreateDirectory", directory$, 0 

Richard.
« Last Edit: Sep 22nd, 2013, 10:03am by admin » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls