Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find *.pdf and list them in a text file

Status
Not open for further replies.

ledzepe

MIS
May 13, 2003
19
0
0
CA
Hi all,

I a newbie with vbs and this question might have been asked a million time already. I need to search a folder/directory for all the pdf file and (1)list them in a text file, (2)display on screen how many pdf and then (3)move them to a different directory. Thanks a million.
 
Do a search for

FileSystemObject
GetFolder
InStr()
Recurse

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
You could also leverage Regular Expressions for your matching tool:

Code:
Option Explicit

Dim fso, FolderName, objFile, objFolder, objFileCol, objRegEx, NewFolderName, PDFCnt, OutStream
Set fso = CreateObject("Scripting.FileSystemObject")

FolderName = "C:\New Folder\"
NewFolderName = "C:\New Folder\Test\"
Set OutStream = fso.OpenTextFile(FolderName & "LOG.TXT",8,True)
Set objFolder = fso.GetFolder(FolderName)
Set objFileCol = objFolder.Files
PDFCnt = 0

Set objRegEx = New RegExp
objRegEx.Pattern = "\.pdf$"
objRegEx.IgnoreCase = True

For Each objFile In objFileCol
     If objRegEx.Test(objFile.Name) Then
           PDFCnt = PDFCnt + 1
           OutStream.WriteLine FolderName & objFile.Name
           fso.MoveFile FolderName & objFile.Name, NewFolderName & objFile.Name
     End If
Next
OutStream.Close
Set OutStream = Nothing
Set fso = Nothing
Set objRegEx = Nothing

wScript.Echo PDFCnt & " PDFs Moved!"

If you want to show the progress on screen you will have to use Internet Explorer object or maybe put this in an HTA.

Swi
 
Thanks Swi, I also made something similar but your code's a bit more elegant than mine.
 
or you can execute a dos command in vbs like this:

dir c:\some_directory\*.pdf > log.txt

this will put the file names in text file log.txt
cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top