PC Review


Reply
Thread Tools Rate Thread

"COMSPEC" Problem

 
 
Masoud
Guest
Posts: n/a
 
      19th Jun 2009
Hello

I used the code for creating a table of file names that there is in
www.rogersaccesslibrary.com (DirectoryList.mdb), but it does not work in my
computer .My computer has windows vista, Access 2007.
Please help me.
Thanks.

 
Reply With Quote
 
 
 
 
Albert D. Kallal
Guest
Posts: n/a
 
      19th Jun 2009
I not sure what that code is/was (I can't see it nor find it).

but, I use:

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, strFil 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 & strFil)

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 (GetAttr(startDir & strTemp) And vbDirectory) = vbDirectory Then
If (strTemp <> ".") And (strTemp <> "..") Then
colfolders.Add strTemp
End If
End If
strTemp = Dir
Loop

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

End Sub

Sub FillDir(startDir As String, dlist As Collection)

build up a list of files, and then
add add to this list, any additional
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



If you wanted to pull the names to a table, then just go:

Dim dlist As New Collection
Dim startDir As String
Dim i As Integer
dim rstData as dao.RecordSet

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
set rstData = currentdb.OpenRecordSet("tblMyFiles")
For i = 1 To dlist.Count
rstData.AddNew
rstData!FileName = dlist(i)
rstData.Update
Next i
rstData.Close

msgbox "done"


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(E-Mail Removed)


 
Reply With Quote
 
Masoud
Guest
Posts: n/a
 
      19th Jun 2009
thank you for your code.

the code i used before is like below (it works in xp,access 2003 but it does
not work in vista, access 2007):

Sub ReadDesktopFolder()
Dim lPid As Long
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection

lPid = Shell(Environ("COMSPEC") & " /c dir " & Chr(34) & "C:\Documents and
Settings\carlrj\Desktop\TestFolder" & Chr(34) & "\*.* /a:-d /b
>c:\myfiles.txt")


cnn.Execute "Delete * from FolderNames"
DoCmd.TransferText acImportDelim, "Myfiles Import Specification",
"tblFiles", "c:\myfiles.txt", False, ""
End Sub


"Albert D. Kallal" wrote:

> I not sure what that code is/was (I can't see it nor find it).
>
> but, I use:
>
> 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, strFil 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 & strFil)
>
> 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 (GetAttr(startDir & strTemp) And vbDirectory) = vbDirectory Then
> If (strTemp <> ".") And (strTemp <> "..") Then
> colfolders.Add strTemp
> End If
> End If
> strTemp = Dir
> Loop
>
> now process each folder (recursion)
> For Each vFolderName In colfolders
> Call FillDir(startDir & vFolderName & "\", strFil, dlist)
> Next vFolderName
>
> End Sub
>
> Sub FillDir(startDir As String, dlist As Collection)
>
> build up a list of files, and then
> add add to this list, any additional
> 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
>
>
>
> If you wanted to pull the names to a table, then just go:
>
> Dim dlist As New Collection
> Dim startDir As String
> Dim i As Integer
> dim rstData as dao.RecordSet
>
> 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
> set rstData = currentdb.OpenRecordSet("tblMyFiles")
> For i = 1 To dlist.Count
> rstData.AddNew
> rstData!FileName = dlist(i)
> rstData.Update
> Next i
> rstData.Close
>
> msgbox "done"
>
>
> --
> Albert D. Kallal (Access MVP)
> Edmonton, Alberta Canada
> (E-Mail Removed)
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Field Names: "LongName", "ShortName", "Code", "Description","Comments" PeteCresswell Microsoft Access 2 25th Feb 2009 11:41 PM
Keep Cmd Window ON TOP when using Shell Environ$("COMSPEC") cmd ?? kev100 via AccessMonster.com Microsoft Access Form Coding 5 1st Aug 2006 04:43 PM
Problem with blank "yes", "no", "cancel" option boxes =?Utf-8?B?Q29saW5HQmxhaW5l?= Windows XP Help 1 3rd Jul 2004 03:35 PM
<FORM METHOD="post" onSubmit="return fieldcheck()" name="orientation" action="http://ws-kitty.BU.edu/AT/survey/orientation/script/write.asp" language="JavaScript"> Joeyej Microsoft ASP .NET 0 4th Jun 2004 08:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:21 AM.