| 
 
| 
|  Author | Topic: pwd equivalent?  (Read 889 times) |  |  
| 
| 
| g3nrw Junior Member
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 74
 
 | 
|  | 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
 
 
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| g3nrw Junior Member
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 74
 
 | 
|  | 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
 
 
 
 
 
 
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| admin Administrator
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 1145
 
 | 
|  | 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:
 
 Test whether the directory exists first.  You can easily do that by attempting to open the virtual file NUL which exists in every directory:Richard.Code:
   exists% = OPENIN(directory$ + "\NUL")
  IF exists% CLOSE #exists% ELSE OSCLI "MKDIR """+directory$+"""" Wrap the MKDIR call in a procedure and trap errors locally:
 Code:
   DEF PROCmkdir(directory$)
  ON ERROR LOCAL ENDPROC
  OSCLI "MKDIR """+directory$+""""
  ENDPROC Use the Windows API, and ignore the returned value:
 Code:
   SYS "CreateDirectory", directory$, 0 
 |  
| 
| « Last Edit: Sep 22nd, 2013, 10:03am by admin » |  Logged |  
 |  |  |  
 |