Page 1 of 1

Getting DIR stuff

Posted: Mon Aug 15, 2005 4:21 pm
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.

Posted: Mon Aug 15, 2005 4:29 pm
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

Posted: Mon Aug 15, 2005 5:29 pm
by {Nathan}
Nope, QB 45 all the way over here.

Posted: Mon Aug 15, 2005 5:50 pm
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.....

Posted: Tue Aug 16, 2005 2:13 pm
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"
*****

Posted: Tue Aug 16, 2005 2:44 pm
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$

Posted: Wed Aug 17, 2005 11:10 am
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