Jump to content
Macro Express Forums

Increment File Number


patgenn123
 Share

Recommended Posts

Hi,

 

I want to be able to count the number of files in a folder(which I know how to do), but I want it to react to the addition of a new file added to the folder and execute the rest of the macro, but only if the folder is bigger than the number previuosly counted.

 

Example: The folder count is 100, but I move a new file making it 101 files. Execute the rest of the macro only if the file count gets larger.

 

Once the macro is executed, the new folder count is 101 and is based on this number afterwards.

 

Can anyone help me with this? I know it's pretty simple, but I am not finding out why I can't do it in the archives.

 

Pat

Link to comment
Share on other sites

  • 2 weeks later...

That's easy. I have a couple of routines that do similar things and depending on exactly what you are doing it may differ greatly as to which way works best.

 

Note: Using a file count is a quick way to indicate change unless there is a possability of a delete and new. Then things get a little more complex but not too difficult. I'll assume it's only going to be adding new files.

 

I would run the count on a schedule and write the number of files to the registry. This way the macro doesn't have to keep running. On first run I would create a list of files and stick them in a text file. Just append the var to a text file seperated by a CRLF (Carrige Return-Line Feed). When the count increases copy that file to a text var. Then repeat with folder and for each file name see if the var holding the entire text file contains your text. When it finds one that is not contained 'break' and use that to do whatever you like with that file name.

 

When you search thru the vars from that file you might want to append your search text with a CRLF. You see you could have two files 11.txt and 1.txt and you will find 1.txt in the accumulated var from file if there was a file before named 11.txt. To if you prepend your text you are using in the "contains" comparison with a CRLF and maybe even append you're sure not to muff it. Oh, you need to write a CRLF to the beginning of that file as well for this trick to work.

 

TO make your own CRLF see my webpage on it and steal my code.

http://bluepointdesign.com/macros/CRLF&TAB.htm

Link to comment
Share on other sites

Cory,

 

I really appreciate your response, but you might as well be speaking Chinese. I do not know what that all means except a few things. I truly appreciate your response. I guess there are many ways to slice this.

 

And yes, I am looking for an end all do all. If a file name is changed, perform the rest of the macro, If a file is added, perform the rest of the macro, if a file is deleted, perform the rest of the macro, If a file is created, perform the rest of the macro. In a nutshell, if there is any change at all, recognize it and perform the rest of the macro.

 

This is a little different from my original post, but I have not a clue on how to start even with the simple stuff.

 

The only problem is, I think I am getting way over my head. I wish I could have someone teach me this stuff. I learn by example. This is slowly sinking in, but not as fast as I want it to.

 

Help!

 

Pat

Link to comment
Share on other sites

If you’re just starting out it would take to long for me to teach you all the things for my solution. I have to be careful because I can easily get sucked into hours of forum help when I should be billing hours! <g> I have to go to LA today but I could help you a bit here and there. If you like we could set up a phone conversation as well. Sometimes these things are easier and quicker by phone. I’ll toss out a couple of random thoughts before I leave…

 

http://bluepointdesign.com/macros/CRLF&TAB.htm I would make use of the CRLF in my solution so read the blurb on my web page. I’ll explain more later.

 

Buy Joe’s book. http://www.macros.com/macexplained.htm Some of it’s a bit fragmented but it’s a wealth of information. And I don’t know how anyone could really make it less fragmented as so much is so interrelated it’s hard to ‘start’ from anywhere without a dozen tangents.

 

Check out the examples: http://www.macros.com/share.htm

And tutorials: http://www.macros.com/share.htm

 

The tutorials have really good working examples you can download that explain certain functions and techniques.

 

If you are I a bind for time the support page http://www.macros.com/support.htm mentions that they can do it for you as well for a fee or they can turn you on to someone who could. I too would be willing to hire out and even teach a few things I know. For billable hours I wouldn’t mind putting you to the front of my queue. I hope that this doesn’t qualify as a solicitation. I’d hate to break any rules here. <g> But I’ll help you in any case, it just might take longer.

 

If you are monitoring for any change you will need a two sided approach. Any time you have two data sets to compare you need to look from both sides. I do this often in Excel seeing if something occurs in one set and visa versa. So you will need to make two lists and compare each for the missing. We can simply loop thru the files looking for them.

 

I’ll hook up with you more later.

Link to comment
Share on other sites

On my way up to Chino I thought of something else for you. I have a macro that monitors for faxes in a folder. Instead of doing the list comparison game I found it easier to use folder manipulations. So the faxes arrive in the ‘received’ folder and the macro looks for any new arrivals. When it finds them id does a little song and dance and moves them to a ‘notified’ folder. I don’t know if this is something you could implement but it makes life a lot easier.

Link to comment
Share on other sites

Great, if you can move files this makes life a lot easier. In my fax macro I have a ‘received’ and ‘notified’ folder. The macro monitors the received folder where a huge MFP drops faxes into as PDFs. All users have the same macro running but depending on who is selected as the fax monitor it just bails out unless you are the chosen one. So the ‘chosen one’ gets an alert and ME pops open the PDF for the user and asks for some info like who it’s for and any special notes and then renames the file a certain way and moves it to the ‘notified’ folder and an email is sent to all the users selected by the chosen one with a hypertext link to the file.

 

As for the folder monitoring part I have the macro run on a schedule every few minutes and it runs a routine to get the first file name in the folder. That was the part I mentioned before. Repeat with folder, Break, Repeat End.This is just a quick and sleazy way to get the first file name. Let’s say we put that in T1. If there are no files the variable will be blank. So then I use an “If” to check for blank. E.g.: If T1 = “” then Macro Stop. This way the macro aborts silently if there are on files. Also it’s simple because we don’t really need an “Else” argument. I like an elegant series of commands like these. If the macro continues then the case is that there is a file and you can use T1 to do whatever you need. When you are done with it move it to a ‘processed’ folder or whatever. It would look like this in the script editor:

 

Repeat with Folder

Break

Repeat End

If Variable %T1% = ""

Macro Stop

End If

Text Box Display: Results

 

You can copy and paste this part into a new macro file if you would like to get touchy feely.

 

<REP3:07:000002:000001:0001:0:01:C:\><BREAK><ENDREP><IFVAR2:1:01:1:><MSTOP><ENDIF><TBOX4:T:1:CenterCenter000278000200:000:Results%T1% is the first file in the root of your hard drive. From here you can do whatever you need with it. Once done you move your file to a different folder.>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...