Solved

Perform an action during a FileSearch

Posted on 1998-11-09
5
197 Views
Last Modified: 2012-05-04
I'd like to know if it is possible to perform an action on the files returned by a filesearch WHEN the search is executing. I'm trying to write a program that will look into a folder and its sub-folders, find all the files haven't been accessed for a certain time, and then rename them. I know the DateLastAccessed property lets me distinguish the files, and the FileSearch method can find the files for me. But if I have to rename the files after the FileSearch, the result list could be huge. Is there any other way to do it? Please advise and thank you.
0
Comment
Question by:jluck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 2

Expert Comment

by:dabellei
ID: 1443985
Every time you find a file use the dovents this will permit you to execute an action at this moment and return to your search after it, and at the same time you can advise the user wich file is update or rename in a label.

0
 

Author Comment

by:jluck
ID: 1443986
Thanks, but dabellei could you please be more specific about your answer? I can't find any document about "dovents". Thanks.
0
 

Author Comment

by:jluck
ID: 1443987
Oh, if you mean DoEvents, please specify how I show trigger the action. Meaning what condition I should use in the IF statement, in order to stop the search everytime it finds the right file. Thanks.
0
 
LVL 2

Accepted Solution

by:
dm_14 earned 150 total points
ID: 1443988
1. Use the Dir command to look at a specific folder
2. for each file returned check its attribute
3. if its attribute is vbdirectory then this is a subdirectory which you will have to look through once you finish processing the current directory (you could store this dir info in an array)
4. if its attribute is a file (not vbdirectory) then check its last accessed time and if required rename the file
5. repeat 2 until no files are returned from the dir function
6. Then pass the array in 3. back to 1.

Use the Doevents in the For .. Next section this will allow your Users to stop the process if required.
0
 

Author Comment

by:jluck
ID: 1443989
Thanks for your answer. Unfortunately my intention is to avoid arrays, cause this could be a big problem when you don't know the size limit. Anyway I found the solution to my problem, which is quite similar to your approach. I am accepting your answer, but I'd like to give 50 points to dabellei cause he/she was quite right in the first place. Hope you both are happy with this arrangement. Thanks.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question