Trying to get "dir /s ..." to work from BASIC

Discussions related to database technologies, file handling, directories and storage
Post Reply
simong42
Posts: 3
Joined: Tue 05 Mar 2019, 20:47

Trying to get "dir /s ..." to work from BASIC

Post by simong42 » Tue 05 Mar 2019, 20:48

I'm trying to execute a 'dir' command from within BASIC but failing.
The command (without the single quotes) is 'dir /s "D:\all files\photos\*.*" > ./dlist.txt', i.e. a recursive directory command, with output directed to a text file.
This works when pasted into a DOS window.

However, when I try and run this through OSCLI, the program attempts to find '/s.BBC' in the current directory, i.e. the /s switch is not recognised as such. Any suggestions?

KenDown
Posts: 52
Joined: Wed 04 Apr 2018, 06:36

Re: Trying to get "dir /s ..." to work from BASIC

Post by KenDown » Wed 06 Mar 2019, 20:51

The simplest suggestion is to not use the /s "switch", whatever it does.

A more complex answer is the BASIC is a programming language whereas DOS is a different language that simply does things - you don't program in it. DOS is already set up to understand and interpret the /s switch, BASIC doesn't understand it - as shown by the /s.bbc, which is the standard file extension used by BASIC if the file lacks an extension. To achieve the recursive effect you want you will have to program recursion into your call.

You may be wondering why OSCLI doesn't pass the command string to DOS. I suspect the answer lies in the recursive nature. OSCLI passes the command, DOS executes it and OSCLI feels that its job it done and doesn't pass on the rest of the command. That's my take on it, anyway.

p_m21987
Posts: 117
Joined: Mon 02 Apr 2018, 21:51

Re: Trying to get "dir /s ..." to work from BASIC

Post by p_m21987 » Thu 07 Mar 2019, 01:52

I'll experiment with this tomorrow to see if I can work out what's going on.

KenDown
Posts: 52
Joined: Wed 04 Apr 2018, 06:36

Re: Trying to get "dir /s ..." to work from BASIC

Post by KenDown » Thu 07 Mar 2019, 17:56

Richard, who appears to be lurking rather than participating, wrote to me to point out that virtually everything I said was wrong! So ignore, please. However he very kindly posted the solution to your problem:

=====
EDIT (DDRM): At Richard's request, I have removed the direct quotes from his email. I think it will be acceptable for me to say: "As a hint to how to handle Windows commands with the same name as a star command within BB4W, have a look at "Introduction to star commands" in the manual, in the section "Similarly named star commands".
===========

Many thanks to Richard, whose knowledge and whose kindness are, as always, unrivalled.

p_m21987
Posts: 117
Joined: Mon 02 Apr 2018, 21:51

Re: Trying to get "dir /s ..." to work from BASIC

Post by p_m21987 » Thu 07 Mar 2019, 20:29

Richard is a really nice guy, he often goes out of his way to help BBC BASIC users. I've got a lot of respect for him.

simong42
Posts: 3
Joined: Tue 05 Mar 2019, 20:47

Re: Trying to get "dir /s ..." to work from BASIC

Post by simong42 » Fri 08 Mar 2019, 06:22

Ah, it's the "leading *" that does it. Many thanks.

The /s switch, by the way, makes a directory list include all subdirectories.

Post Reply