Search File In Folder An Recursive Folder With Dir Function
Hi,
I want to search ActiveX .dll in a expecific folder and in all his recursive folders.
I´ve made a recursive function using dir statement. But dir returns error when it finish in one folder and I want that dir function search in the recursive folders too.
This is my code:
Private Sub search(sFolder As String) Dim sName As String
sName = Dir(sFolder & "", vbDirectory) ' Retrieve the first entry. Do While sName <> "" ' Start the loop. ' Ignore the current directory and the encompassing directory. If sName <> "." And sName <> ".." Then ' Use bitwise comparison to make sure sName is a directory. If (GetAttr(sFolder & "" & sName) And vbDirectory) = vbDirectory Then ' sName is a directory. Debug.Print sFolder & "" & sName ' Display entry only if it search sFolder & "" & sName ElseIf LCase$(Right$(sName, 3)) = "dll" Then ' sNAme is a ActiveX.dll Debug.Print sFolder & "" & sName End If End If sName = Dir ' Get next entry. <= Here happens an error when the function end searching in 1 recursive folder
Debug.Print sName Loop
End Sub
What can I do????
Thanks and regards
Tel
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Search Network Folder For Excel Files & Perform Function
I need to open up a file directory and perform a function on all Excel files in that directory. I have the macro written to perform the task on a specificly named file, I now need to perform a Do Loop on all files in a given directory and the amount of files will change daily.
please help
Thanks in advance
Recursive Or Folder Copy...
Hello All,
It's been awhile and I'm sorry I haven't been more active here, just changed jobs and have been far too busy.
Here's my problem: I need to copy a folder structure and all files in it from one place to another. I can't use an api call because the filename lengths need to be checked before each copy. If they are too long (>259 chars including path) then a message box containing the unusable name needs to be shown w/an 'Ok' button. The copy must then skip that file and finish.
To do this I want to use file system objects and to be honest, I just haven't used them much.
Note to Bill Soo: I love ya dude, but, recursion is out of the question.
Any help would be greatly appreciated.
Thanx In Advance,
->Noah
PS: Here's my pseudo code:
'Create dir structure
'copy files over checking each one before copying
'f/n too long = throw msgbox
'otherwise do copy
Make Folder In Browse For Folder Function
hi, can anyone tell me how to make the 'browse for folder' function to be able to make a new folder.
here is the function i am talking about:
Public Function BrowseFolder(ByVal HwndOwner As Long, ByRef Titre As String) As String
Dim lpIDList As Long
Dim sBuffer As String
Dim BrowseInfo As T_BROWSEINFO
BrowseFolder = ""
With BrowseInfo
.HwndOwner = HwndOwner
.lpszTitle = lstrcat(Titre, "")
.ulFlags = BIF_RETURNONLYFSDIRS
End With
lpIDList = SHBrowseForFolder(BrowseInfo)
If (lpIDList) Then
sBuffer = Space(MAX_PATH)
SHGetPathFromIDList lpIDList, sBuffer
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
BrowseFolder = sBuffer
End If
End Function
im guessing its a flag which can be added but i dont know wat its called.
thanks for any help.
Recursive Delete Of All Files In Folder
Hi everybody and Happy New Year...
I am looking for a way to delete all the files located in a directory and delete them...( with code )...
Does it has something to do with system objects files ?
Also, I want to know if I have to put a DoEvents after each deletion ?
Many Thanks
Upload More Than One Txt File In Same Folder With Same Search String
Hi,
i have to upload data from text file every day. there will be 2 different files
Ex: AA2/3/05 and RR2/3/05 through FTP these files are posted in specific folder.
If we have holiday there will be 2 files of each kind with different dates.
currently i am searching txt file with instr(AA....) and instr(RR....). If exists then upload into table.
My question is if i have two text files with AA as starting filename with different dates...
how should i upload first file first and second file second.... same for the RR.... file also.
>>>>>>>>>>>>>>>>>>>>>>
Edited by - sreddy on 9/13/2005 2:52:17 PM
Open Folder And File - Search (Loop) Help Needed
Hi,
I need some help writing/figuring out if it is possible to perform this using VBA.
I have a main file directory with roughly 100 sub-folders. Within some folders are excel files beginning with the letter ‘J’. I would like to be able to open each sub-folder in turn, if the folder contains a file beginning with a ‘J’ I wish to open the excel doc and search for a field. If the field is found the macro will end, if not the excel document should be closed and the next sub-folder opened and searched.
I am not sure if it is possible to perform this kind of loop using VBA and my main problem comes with my limited knowledge of handling files and folders. Especially where the folder names cannot be hard-coded.
Would anyone be able to explain if this is possible and how one goes about moving through folders in such a way.
Any help would be extremely gratefully received
Edit by Moderator:
Please post Excel questions, in the Excel forum.
Thank you.
Help With VBS Script To Make Folder And Move File Into Folder
Can someone help me make a script so that I can right click on a file (selecting create and move from the menu) and it would make a folder with that name (preferably without the extension) and move the file into the folder. Here is what I have so far (just creates the folder):
Dim NewDir
Function CreateFolder(NewDir)
dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CreateFolder (NewDir)
set objFSO=nothing
End Function
CreateFolder("c: emp est")
How exactly could I do this so I can make an entry in the right-click menu and get it to get the parameters correct?
File/Folder Exists Function
Hi
I have written a simple function that finds if a file/folder exists or not
My problem is that if I delete the files in the folder, that my program reads from, then my function says the folder doesnt exsist why is this?
here is my function...
Code:
Public Function IsPresent(FilePath As String) As Boolean
If Dir(FilePath) = "" Then
IsPresent = False
Else:
IsPresent = True
End If
End Function
When I put this
Code:
If Not IsPresent(App.Path & "Folder1") Then etc
If the folder exists but nothing is in the folder it says the folder doesnt exists, and so my program trys to make the folder which gives me an error because the folder does exist.
Any Ideas?
Browse For File; Folder; Recusive Folder
3 simple things i need help with
X) easyiest way to make a generic browse for file (only) button, nothing fancy
X) same, but for folders only
3) easyiest way to recusively use files in a folder
please post plenty of code for me (vb6)
thanks, Tuxp3
:: NEW::
verification that a user input is a vaild IP i.e. is 0.0.0.0 - 255.255.255.255
New Folder, Folder Exists , File Exist Copy File
Hello,
I want to perform the following task through VB 6.0
How to check Folder if Exist or not , If not exist then create it. If exist then find a given file name Ex. "Abc.Mdb", if exist then delete it and copy new file from App.Path if not exist then copy File from App.Path
Please help me
Farooq
Listing ALL Files In All Sub Folder Including Sub Folder Of A Sub Folder Help
Hi
I have seen this somewhere but can't find it, What I want to do is be able to list the complete structure of a given folder including all Sub folder even if those sub folder have sub folders with files of their own.
that means every file and folder within a parent folder.
Hope ya understand what I'm trying to say their.
Thanks in advance
mick
Recursive File Search
Hey
First off the code im posted isnt all mine, i got it from:
http://www.mvps.org/vbnet/
And adjusted it by removing things i didnt need and updating the names of controls on the form. The code is extremely fast and works fine, the only problem is i cant seem to save the File details to the same file (The code attached doesnt attempt this).
I assume the details are in the WFD type however when accessing this or attempting to save these extra details to the same file i get blanks in a lot of entries.
Basically, does anyone know an API function that will scan through the hard drive, but will allow file details to be saved to? I can only get the code below to save file names correctly, unfortunately.
Thanks a lot.
Gav
Feedback Please - Recursive File Search / Info Grabber
I've been tinkering around here on this module to see what sort of solution I could come up with for searching and returning filenames, times, sizes and attributes for all files found, searching with wildcards and recursing subdirectories.
The attached module is what I have come up with to date.
I'd be interested on any feedback from anyone out there, especially in regards to the file times and sizes for large files (2.2GB and above). Anyone watching my posts over the past few days will know what I mean.
Thanks everyone for your feedback and help.
Folder Search
I have made a testprogram, which should search for folders inside a directory. I have used the following code:
form:
Code:
Private Sub Command1_Click()
Call Bestanden(True)
Text1.Text = glbBedrijfMappenAantal
If glbBedrijfMappenAantal = 0 Then
Text2.Text = "Geen mappen gevonden"
Else
Text2.Text = glbBedrijfMappen(0)
End If
End Sub
Module:
Code:
Option Explicit
Global glbBedrijfMappen() As String
Global glbBedrijfMappenAantal As Integer
Public Function Bestanden(SearchFor As Boolean)
Dim a As String
Dim b As String
Dim C As Integer
Dim Path As String
Dim intChunkSize As Integer
ReDim glbBedrijfMappen(intChunkSize)
intChunkSize = 20
C = 0 ' Begin te tellen bij 0
If SearchFor = True Then ' Dan is het een bedrijfzoekopdracht
Path = "E:VBscriptsPDAtoolin" ' De hoofdmap
End If
a = Dir$(Path, vbDirectory)
b = Dir$(Path)
Do While Len(a) > 0
If a = "." Or a = ".." Or a = "questions" Or a = "answers" Then
'Deze mappen niet meenemen.
Else
If C = UBound(glbBedrijfMappen) Then ' See if we have enough space
ReDim Preserve glbBedrijfMappen(C + intChunkSize) ' Increase array size
End If
If (GetAttr(Path & a) And vbDirectory) = vbDirectory Then ' Is het een map
glbBedrijfMappen(C) = a ' Toevoegen aan array
glbBedrijfMappenAantal = C ' Totaal aantal mappen
End If
a = Dir$ ' Zoek de volgende op
C = C + 1 ' Tel er 1 bij het getal op
End If
Loop
End Function
Problem that occures is that the program Freezes. Which means, using Cntr. Alt Delete I have to shut it off.
I am searching in the this map:
E:VBscriptsPDAtoolin
in it are the maps "answers", "questions", "cyl"
This script should return "cyl" as value of glbBedrijfNaamMappen(0) and should have the value 1 in glbBedrijfNaamMappenAantal
Can someone see the problem (I think it has 2 do with the path I gave, because it seems like it is looping endless.
Folder Search
Hi, I have created a program that launches a specific application when a button is pressed. I have included an options form that enables the user to change the file path and name of the program that is launched. This value is saved in the registry and then used by setting a string value with the REGGetSetting command.
The user also has the option of clicking on a browse button. This opens up an 'Open file' dialog and enabled the user to find the program file them self and select it. The path and name of this file is then entered into the registry. Is there a way of replacing this with a folder selection window instead? Like the ones used in Windows for driver file searching. Ask me if you need futher explanation of my problem (I'm not very good at explaining!).
Thanks in advance!
Search For A Folder
Hey,how can is search C: for folders with the string "Music" in the file name? and then copy a file there using file copy thanks?
so say i had "My Music","bla music" etc the exe wud copy because its read the string music thanks a alot!
Folder Search
Hi all
I have a folder path in this folder for all files I want to add
particular lines (say "Hallow " for time being)
the code I have written works for only 3 levels of sub folders
i.e if the subfolder is c:/try/try1/try2/try3/try4/abc.txt
then that txt file remains unultered....Why?
Wat is the code to overcome this? I want to change every file
in every sub dir....
Nahush
Search For A Folder
hi i whant to search for one or maybe more SPECIFIC folder(s)
but how ?
someone gave me this
Code:
s = Dir$(StartingDirectory, vbDirectory)
Do While Len(s) > 0
If GetAttr(StartingDir & s) = vbDirectory Then
If StartingDir & s = FolderToFind Then
MsgBox "Found: " & StartingDir & s
Exit Do
End If
End If
Loop
but i didnt understand it
Search Folder
Hi,
I have a folder in which I have n number of word Document.
How can I search few words in All those documents.
Example--
In the folder
Suppose all the word doc are Resume of some people.
and I want to search few specific things like asp, .net etc etc.
It would be something like windows search .
How can I create that type of search in asp.net . I m using vb projects
Please let me know.
Thanks
Search Folder
Hi,
Question: I have a folder which can be remove in any location (including server) and can be saved as subfolder.
For example:
C:myFolder can be removed on D: myFolder or \Server
ewLocatoin1NewLocation2myFolder.
How can I find of all physical drives and make a search myFolder, and if not found search on server?
Thanks’
To Search A Folder In A Path
i store different paths dynamically at runtime in a variable...now i should check whether a paticular folder called "BIN" is there in my folder or not...if the folder is not there in the path then i should throw an error...how could this be done?
Search Files Within A Folder
Ok i have make a search on this topic but cant find a suitable answer.
What I want is that how can i do a search and compare within a folder
Example files that i have in a folder listed below.
28-Jan-08.dat
29-Jan-08.dat
Before creating a new .dat file it will compare the filename which is 29-Jan-08with the present date(29-Jan-08) if it exists it will not create it until it is on the next day of the month so bascailly when the time strucks 1200am which is on 30-Jan-08 then it will create a new .dat file which is 30-Jan-08.dat.
So how can i compare it??
I know something like this... but i not sure how can i go about it.
If getfilename != Date() then
Create a new .dat file
end if
anyone thanks.
How To Search For A FOLDER Or DIRECTORY By NAME Only!
Hi all, i just want my program to do the following, kinda like the SEARCH feature in WINDOWS where you just enter a NAME your looking for and WINDOWS brings up everything by that name regarless whether its a FILE, FOLDER, DIRECTORY etc. This is what i want to be able to do:
- Allow the USER to enter just the NAME of the FOLDER or DIRECTORY he/she's looking for.
- I DO NOT want the USER to specify a PATH or manually search a DIRECTORY like WINDOWS EXPLORER lets you.
- The USER can specify if the NAME refers to a FOLDER or a FILE or what-not.
- Once the specified FOLDER or DIRECTORY is found, i want to be able to extract its PATH so my program can pass that PATH to a FUNCTION which then extracts all the files within that FOLDER or DIRECTORY. This is what i need, i appreciate any help you guys AND gals can give me. THANKS in advance!
User Folder Search
I am trying to figure out a way to determine the user by looking at the folder paths. I already know all the different paths for each user. From the search I want to put the person's name into a text box on the form. I will use this text box for reference to set up all the other file paths that I will need.
Example
"C:DocumentsMykal" = Mike
"C:DocumentsJames" = Jim
I've done a search on these boards and I found a few things I thought were along the same lines but nothing has seemed to work so far.
I thank you in advance for your time and help with this.
Thanks,
Mykal
User Folder Search
I am trying to figure out a way to determine the user by looking at the folder paths. I already know all the different paths for each user. From the search I want to put the person's name into a text box on the form. I will use this text box for reference to set up all the other file paths that I will need.
Example
"C:DocumentsMykal" = Mike
"C:DocumentsJames" = Jim
I've done a search on these boards and I found a few things I thought were along the same lines but nothing has seemed to work so far.
I thank you in advance for your time and help with this.
Thanks,
Mykal
Search For Folder *Resolved*
hey all
Can I search for a Folder when the search criteria is not exactly the same as the folder name??
example:
I have a floppy with a file named "Test File 1990 part one.doc"
can i do a search of a dir on my c: drive and return the Folder "Test" using
"Test File 1990 part one.doc" as the search name??
Is there a way to search a dir and return the closest match or matches???
Folder Type Search
Is there a way of determining if a folder is one of the system types of folders eg Desktop, History or Favorites. I use the SHGetFolderPath function to get the path etc, but if I trap the path of a folder how can I test if it is one of the 'system' types.
Thanks in advance.
Folder Search Sweep
Hello,
I creating a program to simplify the usage of offen used programs, and I would like the program to sweep the folder it is currently existing inside for (ie) data.exe
If the program is not inside the current folder then the item menu will denable it for selection.
thank you for who answers
------------------
- m i k e l (Exodus)
Beginner Programmer
Homepage: http://influx.virtualave.net
e-mail: exodus_w@hotmail.com
ICQ: 17527422
FSO Search On Parent Folder
Hello.
Not sure if this is the right place to ask.
I am not an FSO expert by any means and we have been using a script to generate folder content listing on an asp page.
I am looking for a simple FSO search script that would be run on the parent folder for users to search for relevant files with a particular file name?
Thanks in advance for any help.
This is the script we're using:
Quote:
if objFSO.FolderExists(strPhysicalPath) Then
dim x, xx, i, j, tempx
x = 0
For Each objFileItem In objFolderContents
x = x + 1
Next
tempx = x - 1
Dim temps( )
dim tempsd( )
redim temps(x)
redim tempsd(x)
xx = 0
For Each objFileItem In objFolderContents
temps(xx)=objFileItem.Name
tempsd(xx)=objFileItem.DateLastModified
xx = xx + 1
Next
if (sortbydate) then ''sorts folder contents by date
for i = tempx To 0 Step -1
for j = 0 to tempx
if tempsd(j) > tempsd(j+1) then
temp=temps(j+1)
temp2=tempsd(j+1)
temps(j+1)=temps(j)
tempsd(j+1)=tempsd(j)
temps(j)=temp
tempsd(j)=temp2
end if
next
next
x = 1
else
x = 0
end if
if (sortbydate) then
tempx = tempx + 1
for x = tempx To 1 Step -1
select case Ucase(right(temps(x),3))
case "PDF"
strImageType = "pdf.gif"
case "DOC"
strImageType = "doc.gif"
case "HTM"
strImageType = "IEXPLORE1.gif"
case "TML"
strImageType = "IEXPLORE1.gif"
case "XLS"
strImageType = "xls.gif"
case else
strImageType = "document.gif"
end select
if date < tempsd(x)+ strDays then
strNewFile="<font size=""1"" color=""red"" face=""arial"">updated" & strNewFile &"</b><br></font>"
else
strNewFile=""
end if
strLen = Len(temps(x))
if instr(temps(x),"~")=0 then
Response.Write "<img src=""images/doc_images/"& strImageType &""" border=""0"" align=""texttop"" vspace=""1""> <a href=""#"" Onclick=""javascript:Start_large('File:"&strPhysicalPath & Replace(replace(temps(x),"'","'")," ", "%20")&"')""; class=""intranet"" onmouseover=""window.status=('" & strFolder & ": " & left(replace(Replace(temps(x),"_", " "),"'","'"),strLen - 4) & "'); return true;"" onmouseout=""window.status=(' '); return true;"">" & left(Replace(temps(x),"_", " "),strLen - 4) & "</a>" & strNewFile&"<br>" & chr(13) & chr(10)
end if
Next
else
for x = 0 To tempx
select case Ucase(right(temps(x),3))
case "PDF"
strImageType = "pdf.gif"
case "DOC"
strImageType = "doc.gif"
case "HTM"
strImageType = "IEXPLORE1.gif"
case "TML"
strImageType = "IEXPLORE1.gif"
case "XLS"
strImageType = "xls.gif"
case else
strImageType = "document.gif"
end select
if date < tempsd(x)+ strDays then
strNewFile= "updated " & FormatDateTime(date,1)
else
strNewFile=""
end if
strLen = Len(temps(x))
if instr(temps(x),"~")=0 then
Response.Write "<img src=""images/doc_images/"& strImageType &""" border=""0"" align=""texttop"" vspace=""1""> <a href=""#"" Onclick=""javascript:Start_large('File:"&strPhysicalPath & Replace(replace(temps(x),"'","'")," ", "%20")&"')""; class=""intranet"" onmouseover=""window.status=('" & strFolder & ": " & left(replace(Replace(temps(x),"_", " "),"'","'"),strLen - 4) & "'); return true;"" onmouseout=""window.status=(' '); return true;"">" & left(Replace(temps(x),"_", " "),strLen - 4) & "</a><b><font size=""1"" color=""red"" face=""arial""> " & strNewFile &"</b><br></font>" & chr(13) & chr(10)
end if
Next
end if
Set objFile = Nothing
Set objFolder = Nothing
Set objFolderContents = Nothing
end if
Set objFSO = Nothing
Recursive File List Function
I have a function that will return any files in a given folder. But in order to make it also return files in subfolders, i was told i would have to make it recursive. Recursive functions are something ive never had to use yet...and quite frankly i dont understand them. Could someone tell me what modifications i would have to make to this function to make it return subfolder files as well?
VB Code:
Function DirList(strDir As String) As String() 'returns a 0 based array with the files in strDir 'Can contain a pattern such as "*.*" Dim Count As Integer Dim sFiles() As String Dim sFile As String sFile = Dir$(strDir) Count = -1 Do Count = Count + 1 ReDim Preserve sFiles(Count) sFiles(Count) = sFile sFile = Dir$ Loop DirList = sFilesEnd Function
thanks,
Nishant
Search Files In Folder And Subfolders
Hi,
I need to search through every file in a folder and every subfolder for specific text and if the text is found display the file path in a list box. Any help?
Search Folder And All Subfolders For XLS Files
I am looking for a little help with a recursive function that, given a path, searches that folder and all subfolders for XLS files, copies data from 'SheetX!A1:J20' in each XLS file and pasting data into a master XLS file. (It's the API calls I need help with.) Thanks in advance!
Search For A Folder And Return It In A String
I want create a program that copies some directories. While developping the files are in C:VBProjectsFileCopyData.
For an end user of the program, the folders will be on a network drive or a cd.
I want to make my program that it will scan all available drives for a folder (eg folder1) and returns where it was found in a string (eg D:Folder1 if it is on CD, S:DataFolder1 if it is in the users' network home directory, ...).
Then I could use this string for use in a shFileOperations copy action.
I know how to manage it with the filesystemobject but try to use API.
This way I improve my API knowledge
Any ideas of which API to use
List And Search Files In A Folder
Hi all, now i need to open a folder and search for some files have the same extention name, lastly list all the file names.
Eg: the folder contains different kind of files, some files' names are "xxxx.0D9", some files' names are "xxxx.0D3"....etc, so now i need to open the folder and find out all the files named with extention ".0D3" and show the file names out in a textbox.
Could you tell me is there any build in function to open a folder ? (let's say the path of the folder is "C:Documents and SettingsDesktopSample")
or any suggestion? Thank you in avdance !
Search For A Folder In Local Drive
Using the FileSystemObject within a wmi .vbs script, I need someone to help me find a way to:
Search for a folder within a given path and search it with a variable name, (the folder name is unknown). I'm trying to find a folder named *.slt This file is a netscape profile folder, which is randomly generated for each profile for each user on the network.
once the folder is found on either NT (%windir%profilesusernameapplication datamozillaprofiles*.slt) or XP/2k (%homedrive%documents and settingsusernameapplication datamozillaProfiles*.slt)
it will copy a file to that directory.
If someone has a command line script (.cmd or .bat) with finding if a folder exists that will be better than a vbs file. I have found many vbs scripts that find a folder by date or a specific name but none that do what I want.
Thank you in advance!!!!,
P.S. I dont know how to write vb at all, newbie
|