Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Getting file name and Modified date

Hi,
I need to get the file names and modified date for file using 'PDA*.PDF' and
searching all subdirectories
What I have tried

Dir() will only give me the file name

Application.FileSearch to so long to do just one directory

Scripting.FileSystemObject I can't get it to use wild cards for the file name

I think the Scripting.FileSystemObject will do what I want but I need some
help to get it to use wild cards and to search the sub directories

Thanks MarkS

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Getting file name and Modified date

Hello MarkS
If you tried FileSystemObject and couldn't get it to work then I suspect you
have used the like comparison.
In which case I would advise you to watch for upper and lower case.
eg:
"PDAanything.pdf" Like "PDA*.PDF"
will return False.
where
LCase("PDAanything.pdf") Like LCase("PDA*.PDF")
will return True

HTH
Cordially
Pascal

"MarkS" a écrit dans le message de news:
...
Hi,
I need to get the file names and modified date for file using 'PDA*.PDF'
and
searching all subdirectories
What I have tried

Dir() will only give me the file name

Application.FileSearch to so long to do just one directory

Scripting.FileSystemObject I can't get it to use wild cards for the file
name

I think the Scripting.FileSystemObject will do what I want but I need some
help to get it to use wild cards and to search the sub directories

Thanks MarkS



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Getting file name and Modified date

"MarkS" wrote:

Hi,
I need to get the file names and modified date for file using 'PDA*.PDF' and
searching all subdirectories
What I have tried

Dir() will only give me the file name

Application.FileSearch to so long to do just one directory

Scripting.FileSystemObject I can't get it to use wild cards for the file name

I think the Scripting.FileSystemObject will do what I want but I need some
help to get it to use wild cards and to search the sub directories



I don't think you can use wildcards with Scripting.FileSystemObject to list
the files in subfolders (you can use wildcards with FSO.CopyFile and
FSO.CopyFolder methods for source arguments to copy multiple files or
folders). From what I've seen, you need a recursive procedure that would look
like this:

- get the starting folder
- enumerate the files in the starting folder
- check each file to see if it matches your criteria ("PDA" in the file name
and "PDF" extension)
- if it does, get the file last modified date
- enumerate all the subfolders in the starting directory
- repeat the procedure recursively for each subfolder.


Public oFSO As New FileSystemObject


Sub FsoTest()

Call ListFiles("c:\test\")

End Sub


Sub ListFiles(strFolder As String)

Set oFolder = oFSO.GetFolder(strFolder)

For Each oFile In oFolder.Files
If oFSO.GetExtensionName(oFile.Name) = "txt" Then
Debug.Print oFile.Name, oFile.DateLastModified
End If
Next

For Each oSubfolder In oFolder.SubFolders
Call ListFiles(oSubfolder.Path)
Next

End Sub


I don't have files named PDA*.PDF so I used "txt" extension. You would also
need to modify the code to check if the first three characters of oFile.Name
are "PDA".

If you don't like using recursion, you could use the command line Dir
command with /s switch:

cmd /c dir /b/s c:\test\*.txt

You could redirect the output to WshShellExec.StdOut stream, read the stream
line by line, and use FileSystemObject to get the file object for each line
of output, and the last modified date.


Sub WshShellTest()

Dim oWshShell As New WshShell

Set oStdOut = oWshShell.Exec _
("cmd /c dir /b/s c:\test\*.txt").StdOut

Do While Not oStdOut.AtEndOfStream
Set oFile = oFSO.GetFile(oStdOut.ReadLine())
Debug.Print oFile.Name, oFile.DateLastModified
Loop

End Sub


To run this you need to add reference to Windows Script Host Object Model. I
think that what you need also can be done with VBA Dir() and FileDateTime ()
functions. Try searching this group, I'm sure you will find some examples.

--
urkec
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Modified File Organization Roadsignologist Excel Discussion (Misc queries) 3 December 18th 08 04:34 PM
Formula for file modified date Pastel Hughes Excel Discussion (Misc queries) 3 April 4th 08 06:23 PM
insert the date the file was last modified Ted M H Excel Discussion (Misc queries) 5 September 2nd 07 03:28 PM
date file modified Matthew Excel Discussion (Misc queries) 2 October 11th 06 06:52 PM
Get the date a file was modified JustinP Excel Programming 2 September 5th 06 04:54 AM


All times are GMT +1. The time now is 09:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"