Getting DIR stuff

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Getting DIR stuff

Post by {Nathan} »

I am interested in making some utilities for DOS on my old laptop, but I am stuck in a delima. How can I get the contents of a directory, just the files, in a list, with the DIRS seperate? I want to keep my code as clean as possible with this... and I know that some DIR command parameter will do this, but there is no way to seperate the directory(s) from the files.
Image
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

If you're using VBDOS or PDS (I believe) the dir$ has a parameter that that specifies the type of file you're looking for...I believe that doing something like:

DIR$("FileParameters", 16) will only return folders
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

Nope, QB 45 all the way over here.
Image
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

NOt much you can do I think from QB itself...maybe you can SHELL the DOS operations to a file and process that file accordingly.....
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

Try these SHELL statements from your program.

To get a list of all the filenames only:
SHELL "DIR /A-D /B >MYFILES.TXT"

To get a list of all the sub-directories (one level) only:
SHELL "DIR /AD /B >MYDIRS.TXT"

The above assumes that your program is positioned at the directory that you want to see the files and dirs.

If not, and FULLPATH$ contains the path\directory in question, then:
To get a list of all the filenames only:
SHELL "DIR "+FULLPATH$+" /A-D /B >MYFILES.TXT"

To get a list of all the sub-directories (one level) only:
SHELL "DIR "+FULLPATH$+" /AD /B >MYDIRS.TXT"
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

QB71 or FB for DOS

Both have the DIR$() command:

Code: Select all

t$ = DIR$("*.*")
do while t$ <> ""
  print t$
  t$ = DIR$()
loop
You may have to remove the () on the last DIR$
I have left this dump.
Seb McClouth

Post by Seb McClouth »

You can also make use of so called batch-files.
Same I have at mine. I use linux-command because they're
somewhat easier.

You could make for dir ls.bat

Code: Select all

ls.bat
@echo off

if %1 == "-l"  goto lsl

if %1 == "-a" goto lsa

if %1 == "-R" goto lsR

if %1 == "--help" then goto lshelp

dir %2 /b /l /p

goto end

:lsl
dir %2 /Ogn /p
goto end

:lsa
dir %2 /a /p
goto end

:lsR
dir %2 /s /p
goto end

:lshelp
echo LS v.0.0.1
echo.
echo Syntax: LS [-command]
echo                   -a : show all files including hidden files
echo                   -l  : show long list
echo                   -R : show all files in directory and subdirectories
echo.

:end
I hope this helps a bit.

grtz
Seb
Post Reply