PC Review


Reply
Thread Tools Rate Thread

Check File name for its existance in a folder

 
 
=?Utf-8?B?TXVr?=
Guest
Posts: n/a
 
      19th Dec 2006
Hi
I want to check for some particular files (Containing some particular words
like time sheets or April/May 2006….) are already there in a folder or not.
Can I check I mean search whether the particular file is there in folder or
not?

Is this possible with a macro code?

Any help on this is much appreciated
Regards,
Muk

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWFydGluIEZpc2hsb2Nr?=
Guest
Posts: n/a
 
      19th Dec 2006
Muk

You can use the following, it only searchs for one condition at a time so
you need to devise some logic to keep multiple condition results.
See the line with <<<< in it to change the condition.

Sub fso()
Const msoFileTypeExcelWorkbooks = 4

Dim fs As Object 'FileSearch
Dim ff
Dim lRow As Long

Set fs = Application.FileSearch
fs.LookIn = "C:\Documents and Settings\admin\My Documents"
fs.SearchSubFolders = True
fs.TextOrProperty = "Files" '<<< text to find wilds ok
fs.FileType = msoFileTypeExcelWorkbooks
fs.Execute

For Each ff In fs.FoundFiles
lRow = lRow + 1
ActiveSheet.Cells(lRow, 1) = ff
Next

End Sub

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Muk" wrote:

> Hi
> I want to check for some particular files (Containing some particular words
> like time sheets or April/May 2006….) are already there in a folder or not.
> Can I check I mean search whether the particular file is there in folder or
> not?
>
> Is this possible with a macro code?
>
> Any help on this is much appreciated
> Regards,
> Muk
>

 
Reply With Quote
 
=?Utf-8?B?TXVr?=
Guest
Posts: n/a
 
      19th Dec 2006
Martin I do not know why this is not working.

Can you guess why?

"Martin Fishlock" wrote:

> Muk
>
> You can use the following, it only searchs for one condition at a time so
> you need to devise some logic to keep multiple condition results.
> See the line with <<<< in it to change the condition.
>
> Sub fso()
> Const msoFileTypeExcelWorkbooks = 4
>
> Dim fs As Object 'FileSearch
> Dim ff
> Dim lRow As Long
>
> Set fs = Application.FileSearch
> fs.LookIn = "C:\Documents and Settings\admin\My Documents"
> fs.SearchSubFolders = True
> fs.TextOrProperty = "Files" '<<< text to find wilds ok
> fs.FileType = msoFileTypeExcelWorkbooks
> fs.Execute
>
> For Each ff In fs.FoundFiles
> lRow = lRow + 1
> ActiveSheet.Cells(lRow, 1) = ff
> Next
>
> End Sub
>
> --
> Hope this helps
> Martin Fishlock
> Please do not forget to rate this reply.
>
>
> "Muk" wrote:
>
> > Hi
> > I want to check for some particular files (Containing some particular words
> > like time sheets or April/May 2006….) are already there in a folder or not.
> > Can I check I mean search whether the particular file is there in folder or
> > not?
> >
> > Is this possible with a macro code?
> >
> > Any help on this is much appreciated
> > Regards,
> > Muk
> >

 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      19th Dec 2006
from dave peterson


dim teststr as string
teststr = ""
on error resume next
teststr = dir("yourpath\yourfilenamehere")
on error goto 0

if teststr = "" then
'not found
else
'found
end if


--


Gary


"Muk" <(E-Mail Removed)> wrote in message
news:94C65970-8809-4CFE-8153-(E-Mail Removed)...
> Hi
> I want to check for some particular files (Containing some particular
> words
> like time sheets or April/May 2006….) are already there in a folder or
> not.
> Can I check I mean search whether the particular file is there in folder
> or
> not?
>
> Is this possible with a macro code?
>
> Any help on this is much appreciated
> Regards,
> Muk
>


 
Reply With Quote
 
=?Utf-8?B?TXVr?=
Guest
Posts: n/a
 
      19th Dec 2006
Gary; I am sorry as I believe that I haven't explained my problem correctly.
Your Code is working but really what I want is to find is files which
contain some particular contents of word in the Name.
Like "Timesheets" or "2006" or "January"
and to make a list of the same

Regards,
Muk

"Gary Keramidas" wrote:

> from dave peterson
>
>
> dim teststr as string
> teststr = ""
> on error resume next
> teststr = dir("yourpath\yourfilenamehere")
> on error goto 0
>
> if teststr = "" then
> 'not found
> else
> 'found
> end if
>
>
> --
>
>
> Gary
>
>
> "Muk" <(E-Mail Removed)> wrote in message
> news:94C65970-8809-4CFE-8153-(E-Mail Removed)...
> > Hi
> > I want to check for some particular files (Containing some particular
> > words
> > like time sheets or April/May 2006….) are already there in a folder or
> > not.
> > Can I check I mean search whether the particular file is there in folder
> > or
> > not?
> >
> > Is this possible with a macro code?
> >
> > Any help on this is much appreciated
> > Regards,
> > Muk
> >

>
>

 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      19th Dec 2006
this will display a message box for all files with 2006 in the name of the
default folder.

add the path you want to check and change 2006 to something you want to
search for
fName = Dir("C:\MyFolder\*2006*.xls")


Option Explicit
Dim fname As String
Sub test()
fname = Dir("*2001*.xls") 'Do While fname <> ""
MsgBox fname
fname = Dir()
Loop
End Sub


--


Gary


"Muk" <(E-Mail Removed)> wrote in message
news:7CE18BF9-0D59-497A-90A6-(E-Mail Removed)...
> Gary; I am sorry as I believe that I haven't explained my problem
> correctly.
> Your Code is working but really what I want is to find is files which
> contain some particular contents of word in the Name.
> Like "Timesheets" or "2006" or "January"
> and to make a list of the same
>
> Regards,
> Muk
>
> "Gary Keramidas" wrote:
>
>> from dave peterson
>>
>>
>> dim teststr as string
>> teststr = ""
>> on error resume next
>> teststr = dir("yourpath\yourfilenamehere")
>> on error goto 0
>>
>> if teststr = "" then
>> 'not found
>> else
>> 'found
>> end if
>>
>>
>> --
>>
>>
>> Gary
>>
>>
>> "Muk" <(E-Mail Removed)> wrote in message
>> news:94C65970-8809-4CFE-8153-(E-Mail Removed)...
>> > Hi
>> > I want to check for some particular files (Containing some particular
>> > words
>> > like time sheets or April/May 2006….) are already there in a folder or
>> > not.
>> > Can I check I mean search whether the particular file is there in
>> > folder
>> > or
>> > not?
>> >
>> > Is this possible with a macro code?
>> >
>> > Any help on this is much appreciated
>> > Regards,
>> > Muk
>> >

>>
>>


 
Reply With Quote
 
=?Utf-8?B?TWFydGluIEZpc2hsb2Nr?=
Guest
Posts: n/a
 
      19th Dec 2006
It is strange as it works on mine.

Maybe you need a reference set.

What is the error saying?
--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Muk" wrote:

> Martin I do not know why this is not working.
>
> Can you guess why?
>
> "Martin Fishlock" wrote:
>
> > Muk
> >
> > You can use the following, it only searchs for one condition at a time so
> > you need to devise some logic to keep multiple condition results.
> > See the line with <<<< in it to change the condition.
> >
> > Sub fso()
> > Const msoFileTypeExcelWorkbooks = 4
> >
> > Dim fs As Object 'FileSearch
> > Dim ff
> > Dim lRow As Long
> >
> > Set fs = Application.FileSearch
> > fs.LookIn = "C:\Documents and Settings\admin\My Documents"
> > fs.SearchSubFolders = True
> > fs.TextOrProperty = "Files" '<<< text to find wilds ok
> > fs.FileType = msoFileTypeExcelWorkbooks
> > fs.Execute
> >
> > For Each ff In fs.FoundFiles
> > lRow = lRow + 1
> > ActiveSheet.Cells(lRow, 1) = ff
> > Next
> >
> > End Sub
> >
> > --
> > Hope this helps
> > Martin Fishlock
> > Please do not forget to rate this reply.
> >
> >
> > "Muk" wrote:
> >
> > > Hi
> > > I want to check for some particular files (Containing some particular words
> > > like time sheets or April/May 2006….) are already there in a folder or not.
> > > Can I check I mean search whether the particular file is there in folder or
> > > not?
> > >
> > > Is this possible with a macro code?
> > >
> > > Any help on this is much appreciated
> > > Regards,
> > > Muk
> > >

 
Reply With Quote
 
=?Utf-8?B?TXVr?=
Guest
Posts: n/a
 
      19th Dec 2006
Code runs with no files found
I mean ff (Foundfiles) = Empty
NO Error Message

"Martin Fishlock" wrote:

> It is strange as it works on mine.
>
> Maybe you need a reference set.
>
> What is the error saying?
> --
> Hope this helps
> Martin Fishlock
> Please do not forget to rate this reply.
>
>
> "Muk" wrote:
>
> > Martin I do not know why this is not working.
> >
> > Can you guess why?
> >
> > "Martin Fishlock" wrote:
> >
> > > Muk
> > >
> > > You can use the following, it only searchs for one condition at a time so
> > > you need to devise some logic to keep multiple condition results.
> > > See the line with <<<< in it to change the condition.
> > >
> > > Sub fso()
> > > Const msoFileTypeExcelWorkbooks = 4
> > >
> > > Dim fs As Object 'FileSearch
> > > Dim ff
> > > Dim lRow As Long
> > >
> > > Set fs = Application.FileSearch
> > > fs.LookIn = "C:\Documents and Settings\admin\My Documents"
> > > fs.SearchSubFolders = True
> > > fs.TextOrProperty = "Files" '<<< text to find wilds ok
> > > fs.FileType = msoFileTypeExcelWorkbooks
> > > fs.Execute
> > >
> > > For Each ff In fs.FoundFiles
> > > lRow = lRow + 1
> > > ActiveSheet.Cells(lRow, 1) = ff
> > > Next
> > >
> > > End Sub
> > >
> > > --
> > > Hope this helps
> > > Martin Fishlock
> > > Please do not forget to rate this reply.
> > >
> > >
> > > "Muk" wrote:
> > >
> > > > Hi
> > > > I want to check for some particular files (Containing some particular words
> > > > like time sheets or April/May 2006….) are already there in a folder or not.
> > > > Can I check I mean search whether the particular file is there in folder or
> > > > not?
> > > >
> > > > Is this possible with a macro code?
> > > >
> > > > Any help on this is much appreciated
> > > > Regards,
> > > > Muk
> > > >

 
Reply With Quote
 
=?Utf-8?B?TXVr?=
Guest
Posts: n/a
 
      19th Dec 2006
Thanks Gary

This worked and solved my problem

Thank indeed
Regards,
Muk

"Gary Keramidas" wrote:

> this will display a message box for all files with 2006 in the name of the
> default folder.
>
> add the path you want to check and change 2006 to something you want to
> search for
> fName = Dir("C:\MyFolder\*2006*.xls")
>
>
> Option Explicit
> Dim fname As String
> Sub test()
> fname = Dir("*2001*.xls") 'Do While fname <> ""
> MsgBox fname
> fname = Dir()
> Loop
> End Sub
>
>
> --
>
>
> Gary
>
>
> "Muk" <(E-Mail Removed)> wrote in message
> news:7CE18BF9-0D59-497A-90A6-(E-Mail Removed)...
> > Gary; I am sorry as I believe that I haven't explained my problem
> > correctly.
> > Your Code is working but really what I want is to find is files which
> > contain some particular contents of word in the Name.
> > Like "Timesheets" or "2006" or "January"
> > and to make a list of the same
> >
> > Regards,
> > Muk
> >
> > "Gary Keramidas" wrote:
> >
> >> from dave peterson
> >>
> >>
> >> dim teststr as string
> >> teststr = ""
> >> on error resume next
> >> teststr = dir("yourpath\yourfilenamehere")
> >> on error goto 0
> >>
> >> if teststr = "" then
> >> 'not found
> >> else
> >> 'found
> >> end if
> >>
> >>
> >> --
> >>
> >>
> >> Gary
> >>
> >>
> >> "Muk" <(E-Mail Removed)> wrote in message
> >> news:94C65970-8809-4CFE-8153-(E-Mail Removed)...
> >> > Hi
> >> > I want to check for some particular files (Containing some particular
> >> > words
> >> > like time sheets or April/May 2006….) are already there in a folder or
> >> > not.
> >> > Can I check I mean search whether the particular file is there in
> >> > folder
> >> > or
> >> > not?
> >> >
> >> > Is this possible with a macro code?
> >> >
> >> > Any help on this is much appreciated
> >> > Regards,
> >> > Muk
> >> >
> >>
> >>

>
>

 
Reply With Quote
 
=?Utf-8?B?TWFydGluIEZpc2hsb2Nr?=
Guest
Posts: n/a
 
      19th Dec 2006
This one actually looke in the files for the text not the file names.

No problem Gary provided you with a solution.
--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Muk" wrote:

> Code runs with no files found
> I mean ff (Foundfiles) = Empty
> NO Error Message
>
> "Martin Fishlock" wrote:
>
> > It is strange as it works on mine.
> >
> > Maybe you need a reference set.
> >
> > What is the error saying?
> > --
> > Hope this helps
> > Martin Fishlock
> > Please do not forget to rate this reply.
> >
> >
> > "Muk" wrote:
> >
> > > Martin I do not know why this is not working.
> > >
> > > Can you guess why?
> > >
> > > "Martin Fishlock" wrote:
> > >
> > > > Muk
> > > >
> > > > You can use the following, it only searchs for one condition at a time so
> > > > you need to devise some logic to keep multiple condition results.
> > > > See the line with <<<< in it to change the condition.
> > > >
> > > > Sub fso()
> > > > Const msoFileTypeExcelWorkbooks = 4
> > > >
> > > > Dim fs As Object 'FileSearch
> > > > Dim ff
> > > > Dim lRow As Long
> > > >
> > > > Set fs = Application.FileSearch
> > > > fs.LookIn = "C:\Documents and Settings\admin\My Documents"
> > > > fs.SearchSubFolders = True
> > > > fs.TextOrProperty = "Files" '<<< text to find wilds ok
> > > > fs.FileType = msoFileTypeExcelWorkbooks
> > > > fs.Execute
> > > >
> > > > For Each ff In fs.FoundFiles
> > > > lRow = lRow + 1
> > > > ActiveSheet.Cells(lRow, 1) = ff
> > > > Next
> > > >
> > > > End Sub
> > > >
> > > > --
> > > > Hope this helps
> > > > Martin Fishlock
> > > > Please do not forget to rate this reply.
> > > >
> > > >
> > > > "Muk" wrote:
> > > >
> > > > > Hi
> > > > > I want to check for some particular files (Containing some particular words
> > > > > like time sheets or April/May 2006….) are already there in a folder or not.
> > > > > Can I check I mean search whether the particular file is there in folder or
> > > > > not?
> > > > >
> > > > > Is this possible with a macro code?
> > > > >
> > > > > Any help on this is much appreciated
> > > > > Regards,
> > > > > Muk
> > > > >

 
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
How check multiple file existance on FTP server? Cirene Microsoft ASP .NET 1 26th Aug 2008 04:34 PM
Module to check folder existance rahmad Microsoft Access Form Coding 3 3rd Feb 2008 01:05 PM
Check for file existance =?Utf-8?B?Um9u?= Microsoft Access Forms 4 26th Jan 2006 04:41 PM
Can a formula check for existance of a file =?Utf-8?B?QmlnV29vZg==?= Microsoft Excel Worksheet Functions 6 13th Aug 2004 01:16 AM
check Existance of a file on different machine Ajit Microsoft ASP .NET 5 26th Sep 2003 11:59 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:25 AM.