CheckFiles

kreshnr

Board Regular
Joined
Jan 31, 2007
Messages
70
Hi All,
I am using below mentioned Code for checking if certain file exist on Path.
Its working on my home PC (XP SP2 Excel 2003).
BUT its not working on my office PC (XP SP2 Excel 2003).

Can somebody tell me why its not working in my office PC ( or if its missing something, then from where can i download it.)

Sub CheckFiles()
Const strFolder = "C:\Documents and Settings\kreshnr\Desktop\Test"
Dim fso, msg, i
Dim rngData As Range

Set fso = CreateObject("Scripting.FileSystemObject")
Set rngData = Sheets("Sheet1").Range("A1")

With rngData
Do While .Offset(i, 0).Value <> ""
If (fso.FileExists(strFolder & .Offset(i, 0).Value & ". ")) Then
.Offset(i, 2).Value = "Yes"
Else
.Offset(i, 2).Value = "No"
End If
i = i + 1
Loop
End With
End Sub

Regards

Kreshnr
 
Hi Kenneth,Jim

Thanx for ur time and efforts for this, i will try to explain my query more clearly.


Jim,

Sub sSubFolders() - is not working for me, Error "Project library not found"

Sub List_Files() - is not giving me any sort of error , but its just writing these values on range A5:H5 (Below mentioned)

Filename Created Last changed Size Type Drive Folder Path

Kenneth,

What i am looking for is that

If i give Range A1:A100 with file names(or first or last part of file name) and on Range B1:B100 is the Path (Complete Path or few folder above the sub folders which contain the requested files), then it should return with below mentioned results on offset columns.

Matched Filename, Created, Last changed,Path,Owner



Pls download example file

http://rapidshare.com/files/180531284/Kenneth.zip.html


Excel 2003, XP SP 2, (May be in my machine i cant run wscript.)


Regards

Kreshnr
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I don't see any logic to what you need. If you are doing a wildcard search and searching the path in column B and then subfolders from it, you could have more that one match. On more searches of column A and B for the next row(s) you could have duplicates.

Maybe it is a typo but let's look at A4:C4: last_ver006, D:\test\try\04\older\oldest, kreshnr_last_ver003. As you can see, C4 does not match any criteria in A4.

Your Dir command, after some tweaks, for checking if the file is in Row 4 would be:
Code:
Dir("D:\test\try\04\older\oldest\* last_ver006*.xls", vbDirectory)<>""

Maybe this is more what you wanted.
1. Wildcard search in folder and subfolders for each row's wildcard filename in Column A that would be: "*" & A1 & "*.xls". Column B would be the root folder. (Do not use the FSO method.)
2. Sort the found files.
3. Remove duplicates.
4. Post the results to another sheet in the format of Sheet1.

Is this more what you had in mind?
 
Upvote 0
Hi Kenneth,Joe,

I m still testing it on more then one machine and across different servers.

i will keep u posted with more clear queries..

I really appreciate ur time and efforts.

But the basic idea is

Check the files from certain Path/sub folders inside them.

then return with result "Yes or "No" and "Date Created","Date Modified" and "Owner".


I want more criteria, but for now i will test this first on all machines then i will go ahead for more conditions.



Regards

Kreshnr

(Pls post ur full codes and options).
 
Upvote 0
Hi Kenneth,
Thanx for ur wonderful solution, below is the code which tel me if the file/folder exist on "D:\Test\" and match it with Range "A1" and return with result on Column "B1" with "Yes" or "No".
And this is working on my machine and across all servers and different new and old machines perfectly.

No i just want to add few more criteria to it.
it should give me File Owner, Date Created and Date Modified on offset Column C,D and E.

( just to remind u that FSO wscript and filesystemobject codes doesn't work on my Machine).


Sub CheckFilesandfolders()
Const strFolder = "D:\Test\"
Dim msg, i
Dim rngData As Range

Set rngData = Sheets("Sheet1").Range("A1")

With rngData
Do While .Offset(i, 0).Value <> ""
If Dir(strFolder & "\" & .Offset(i, 0).Value, vbDirectory) <> "" Then
.Offset(i, 1).Value = "Yes"
Else
.Offset(i, 1).Value = "No"
End If
i = i + 1
Loop
End With
End Sub


Regards

Kreshnr
 
Upvote 0
We could use API calls to get the dates. To get the Owner Name, you will have to either open the file and get the document properties or use dsofile.dll. DSOfile.dll can get some file properties with the file closed.

Chip Pearson has details and macros for getting file properties using both methods on his site. I recommend the dsofile.dll method. After getting that file and the Module with Chip's routine, if you still need help post back.
 
Upvote 0
Upvote 0
I guess you know that it is using fso methods.

It would seem to do what you want but it is slow. You might want to add some speed routines as those that I posted at vbaexpress.
 
Upvote 0
Hey Kenneth,
I just noticed u were there in the thread repliers. :).

Thanx Kenneth for helping ignorant noobs like me.

Thanx and Regards

Kreshnr
 
Upvote 0
Kenneth is this the problem with slow / fast process, i dont know i m too noob to understand this .. i tried your code but still i haven't got the author/owner.

can u do it for me and upload it please.

(I also Updated my dsofile directory.. )

Thanx and Regards

Kreshnr
 
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,106
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top