473,408 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Calling an MS-DOS command

I would like to run an MS-DOS command from Access (VBA) in order to read
a directory tree (into an external file). The command works OK from the
command (DOS) window (in XP) but I can't seem to get it to work from
MS-Access (2003). I tried a simplified command, DIR, but also this
wouldn't work.

I have been using the following syntax:

Shell("DIR")

.... which is maybe wrong?

I'm sure that this is a simple thing and am hoping that someone out
there can give me a quick tip?

Many thanks,
Alan Searle
Feb 21 '06 #1
7 23273
Br
Alan Searle wrote:
I would like to run an MS-DOS command from Access (VBA) in order to
read a directory tree (into an external file). The command works OK
from the command (DOS) window (in XP) but I can't seem to get it to
work from MS-Access (2003). I tried a simplified command, DIR, but
also this wouldn't work.

I have been using the following syntax:

Shell("DIR")

... which is maybe wrong?

I'm sure that this is a simple thing and am hoping that someone out
there can give me a quick tip?

Many thanks,
Alan Searle


Can't you use repeated calls to Dir() ?

--
regards,

Br@dley
Feb 21 '06 #2
Hi Br@dley,

Yes, I have been using dir() but want to retrieve a whole directory tree
and have found that there is a rather neat MS-DOS one-liner that will do
all the leg-work for me. This is ...

dir c:\mydir /a:d /b /s>dirs.txt

i.e. it will throw the whole directory tree for the base directory
c:\mydir out to the text file dirs.txt.

If I can get it to run from VBA, then it will save me a lot of coding.
All I need to know is how to call DOS from VBA: the shell() command
doesn't seem to work.

Or maybe you know of a better/simplier way for 'grabbing' full listings
of directory trees in VBA?

Many thanks,
Alan.

Br@dley schrieb:
Alan Searle wrote:
I would like to run an MS-DOS command from Access (VBA) in order to
read a directory tree (into an external file). The command works OK
from the command (DOS) window (in XP) but I can't seem to get it to
work from MS-Access (2003). I tried a simplified command, DIR, but
also this wouldn't work.

I have been using the following syntax:

Shell("DIR")

... which is maybe wrong?

I'm sure that this is a simple thing and am hoping that someone out
there can give me a quick tip?

Many thanks,
Alan Searle

Can't you use repeated calls to Dir() ?

Feb 21 '06 #3
Br
Alan Searle wrote:
Hi Br@dley,

Yes, I have been using dir() but want to retrieve a whole directory
tree and have found that there is a rather neat MS-DOS one-liner that
will do all the leg-work for me. This is ...

dir c:\mydir /a:d /b /s>dirs.txt

i.e. it will throw the whole directory tree for the base directory
c:\mydir out to the text file dirs.txt.

If I can get it to run from VBA, then it will save me a lot of coding.
All I need to know is how to call DOS from VBA: the shell() command
doesn't seem to work.

Or maybe you know of a better/simplier way for 'grabbing' full
listings of directory trees in VBA?

Many thanks,
Alan.
Not sure if this will help....

My guess would be to use the FileSystem object.

http://www.mcse.ms/archive147-2004-6-818078.html

http://pubs.logicalexpressions.com/p...cle.asp?ID=410

Br@dley schrieb:
Alan Searle wrote:
I would like to run an MS-DOS command from Access (VBA) in order to
read a directory tree (into an external file). The command works OK
from the command (DOS) window (in XP) but I can't seem to get it to
work from MS-Access (2003). I tried a simplified command, DIR, but
also this wouldn't work.

I have been using the following syntax:

Shell("DIR")

... which is maybe wrong?

I'm sure that this is a simple thing and am hoping that someone out
there can give me a quick tip?

Many thanks,
Alan Searle

Can't you use repeated calls to Dir() ?


--
regards,

Br@dley
Feb 21 '06 #4
On Tue, 21 Feb 2006 11:39:53 +0100, Alan Searle
<aj*******@xxxyahoo.com> wrote:

How about:
Shell "cmd.exe /c <yourcommand>"

-Tom.

Hi Br@dley,

Yes, I have been using dir() but want to retrieve a whole directory tree
and have found that there is a rather neat MS-DOS one-liner that will do
all the leg-work for me. This is ...

dir c:\mydir /a:d /b /s>dirs.txt

i.e. it will throw the whole directory tree for the base directory
c:\mydir out to the text file dirs.txt.

If I can get it to run from VBA, then it will save me a lot of coding.
All I need to know is how to call DOS from VBA: the shell() command
doesn't seem to work.

Or maybe you know of a better/simplier way for 'grabbing' full listings
of directory trees in VBA?

Many thanks,
Alan.

Br@dley schrieb:
Alan Searle wrote:
I would like to run an MS-DOS command from Access (VBA) in order to
read a directory tree (into an external file). The command works OK
from the command (DOS) window (in XP) but I can't seem to get it to
work from MS-Access (2003). I tried a simplified command, DIR, but
also this wouldn't work.

I have been using the following syntax:

Shell("DIR")

... which is maybe wrong?

I'm sure that this is a simple thing and am hoping that someone out
there can give me a quick tip?

Many thanks,
Alan Searle

Can't you use repeated calls to Dir() ?


Feb 21 '06 #5
Ah-ha, yes, this is exactly what I need.

Thanks very much Tom.

It's simple really, isn't it? :-)

Cheers,
Alan.

Tom van Stiphout schrieb:
On Tue, 21 Feb 2006 11:39:53 +0100, Alan Searle
<aj*******@xxxyahoo.com> wrote:

How about:
Shell "cmd.exe /c <yourcommand>"

-Tom.
Hi Br@dley,

Yes, I have been using dir() but want to retrieve a whole directory tree
and have found that there is a rather neat MS-DOS one-liner that will do
all the leg-work for me. This is ...

dir c:\mydir /a:d /b /s>dirs.txt

i.e. it will throw the whole directory tree for the base directory
c:\mydir out to the text file dirs.txt.

If I can get it to run from VBA, then it will save me a lot of coding.
All I need to know is how to call DOS from VBA: the shell() command
doesn't seem to work.

Or maybe you know of a better/simplier way for 'grabbing' full listings
of directory trees in VBA?

Many thanks,
Alan.

Br@dley schrieb:
Alan Searle wrote:
I would like to run an MS-DOS command from Access (VBA) in order to
read a directory tree (into an external file). The command works OK

from the command (DOS) window (in XP) but I can't seem to get it to

work from MS-Access (2003). I tried a simplified command, DIR, but
also this wouldn't work.

I have been using the following syntax:

Shell("DIR")

... which is maybe wrong?

I'm sure that this is a simple thing and am hoping that someone out
there can give me a quick tip?

Many thanks,
Alan Searle
Can't you use repeated calls to Dir() ?


Feb 21 '06 #6
> Yes, I have been using dir() but want to retrieve a whole directory tree
and have found that there is a rather neat MS-DOS one-liner that will do
all the leg-work for me. This is ...


Well, you can use dir..and some recusrion to traverse the tree....

Here is my code...

The first sub shows how to use the routine....
Sub dirTest()

Dim dlist As New Collection
Dim startDir As String
Dim i As Integer

startDir = "C:\access\"
Call FillDir(startDir, dlist)

MsgBox "there are " & dlist.Count & " in the dir"

' lets printout the stuff into debug window for a test

For i = 1 To dlist.Count
Debug.Print dlist(i)
Next i

End Sub
Sub FillDir(startDir As String, dlist As Collection)

' build up a list of files, and then
' add add to this list, any additinal
' folders

Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant

strTemp = Dir(startDir)

Do While strTemp <> ""
dlist.Add startDir & strTemp
strTemp = Dir
Loop

' now build a list of additional folders
strTemp = Dir(startDir & "*.", vbDirectory)

Do While strTemp <> ""
If (strTemp <> ".") And (strTemp <> "..") Then
colFolders.Add strTemp
End If
strTemp = Dir
Loop

' now process each folder (recursion)
For Each vFolderName In colFolders
Call FillDir(startDir & vFolderName & "\", dlist)
Next vFolderName

End Sub
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal
Feb 22 '06 #7
Hi Albert,

Thanks very much for this. I'll give it a try and, indeed, it may be
better to use your code than to call DOS commands. I'll weigh up the
pros and cons.

Regards,
Alan.

Albert D. Kallal schrieb:
Yes, I have been using dir() but want to retrieve a whole directory tree
and have found that there is a rather neat MS-DOS one-liner that will do
all the leg-work for me. This is ...

Well, you can use dir..and some recusrion to traverse the tree....

Here is my code...

The first sub shows how to use the routine....
Sub dirTest()

Dim dlist As New Collection
Dim startDir As String
Dim i As Integer

startDir = "C:\access\"
Call FillDir(startDir, dlist)

MsgBox "there are " & dlist.Count & " in the dir"

' lets printout the stuff into debug window for a test

For i = 1 To dlist.Count
Debug.Print dlist(i)
Next i

End Sub
Sub FillDir(startDir As String, dlist As Collection)

' build up a list of files, and then
' add add to this list, any additinal
' folders

Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant

strTemp = Dir(startDir)

Do While strTemp <> ""
dlist.Add startDir & strTemp
strTemp = Dir
Loop

' now build a list of additional folders
strTemp = Dir(startDir & "*.", vbDirectory)

Do While strTemp <> ""
If (strTemp <> ".") And (strTemp <> "..") Then
colFolders.Add strTemp
End If
strTemp = Dir
Loop

' now process each folder (recursion)
For Each vFolderName In colFolders
Call FillDir(startDir & vFolderName & "\", dlist)
Next vFolderName

End Sub

Mar 2 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Jeager | last post by:
Why is it, Microsoft manage to write operating systems and office applications with every bell and whistle facility known to man. Yet, even after years and years of development they still cannot...
10
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
8
by: Rob Kellow | last post by:
Hello, I'm working on an application for use within my company on our intranet that will be used to gather some information and store some of the info in a SQL Server database and the rest of the...
0
by: Yohancef Chin | last post by:
Hi, Being fairly new to .NET I am looking for a way to call MS Word from an event on a webform, and after the user is finished save that created document to an SQL Server database. Has anyone...
1
by: Norton | last post by:
Hi all , i would like to make a small utility which allow me to reformat the sql statement from clipboard. I am finding ways which allow me to make use of MS SQL's Query Designer. ...
0
by: AlexanderTodorovic | last post by:
Hello Everyone, I'm developing a client application in which the users need an expression builder as provided in MS Access 2003. I would like to use the expression builder in a C# application....
14
by: krishna1412 | last post by:
Currently i am working in a project of report generation in MS ACCESS. The tables are in sql server 2000. I have to write stored proc in ms access. Illustration: I am having a stored proc...
3
by: Touseef | last post by:
Hi , I call a report but nothing happens except a busy cursor on the screen. What could be the possible reasons for that ?? Taq
5
by: VMI | last post by:
How can I call the Microsoft Word Letter Wizard from within a C# Windows application? And once I open the Letter Wizard from the application, can I automatically paste text on one of the fields...
10
by: bhuvard | last post by:
Hi, Will anybody please help me? I have a MS Access Database with 1 Tabel and 2 queries. e.g. Tabel "client": Client containing fields name,address,city,state,ziip query1 "allClient":...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.