Jump to content
Macro Express Forums

Working Example of Directory Modification


Recommended Posts

Hello everyone,

 

I am very interested in buying ME Pro. From what I've seen, it looks awesome!

 

However, I was wondering if anyone has an example of how the macro is able to check which file is deleted or added using Directory Modification.

 

I would assume that the best way to approach it is to start with a huge text file using Repeat with Folder(using the full file path) to chew through all file names, use "Set Value from File" after the file is created, then when the change happens, fire the macro where the the second part of the macro would compare to the text file to see if the Variable "contains or does not contain". However, the activation triggers are confusing because if I want to have a macro check if a file was deleted, I would have to run the text file against another Repeat with Folder command. If a file was added, then I would have to run the second part of the macro against the text file using the text file process command. This is a lot of work and I am sure the macro would take some time to do both because the activation trigger is not broken down further.

 

So how can i have a simple macro check if either one has happened in a simple elegant way? One that instantly catches the change and nails down the exact area of change?

 

Thank you,

 

Pat

Link to comment
Share on other sites

I've never used this facility. It may be quicker to get ME to flag an event then use another program to actually find the change.

 

With ME I surmise you would have to make a list of the files at the start and then compare to the list after the flag.

 

Rather than process the entire list you could be smart about it, like you would do manually.

Check the filenames about halfway down the list

If the filenames are the same the change is in the bottom half

Otherwise the change is in the top half

Repeat a few times (with the halfway) to get close to the change.

 

You would have to work out relative speeds of the above logic versus processing every filename. Let's say you have a list of 4,000 files. To get to #2,000, Repeat with Folder but don't do anything other than increment a counter (very quick). When the counter reaches the goal, then read the filename, End Repeat. Your existing list you can Text File Process and simply process line # 2,000.

 

This is an idea only, I've never tried it.

Link to comment
Share on other sites

I don't recommend a binary (splitting) search unless the file list is really huge. It is way faster on large directories but even at that the speed is most likely not a concern. I have some macros that plow through thousands of directories and it happens in milliseconds. In fact I have one that goes thru 25k folders and loads them all in an array. That part by itself takes 1 second (41 µS each).

 

Also taking one value and comparing every value is really quick. In the example above I had an array of 25k folder names and I run thru them doing a comparison to each one and that took 0.9s (.34 µS each). Interestingly it was the same for "if equals" and "if contains".

 

In the case of this macro I decided against adding the complexity of a binary search because at the end of the day it didn't cost me anything and I subscribe to K.I.S.S. whenever possible.

Link to comment
Share on other sites

I have a macro that does half of this.

.....................................................

I download almost all my TV using BitTorrent using the RSS auto downloaders but sometimes the website I subscribe to will miss an episode. Problem is I usually delete after watching so I often would lose track. So I created a macro that every time the "download" directory gets modified the macro runs. The macro maintains an alphabetical text file log of every file that arrives. When the macro runs it reads the file into a temp var then splits it into an array using CRLF. Then it runs thru every file in the folder and if it finds a file that doesn't exist in the list it adds it to the array in alphabetical order. If it ever finds an equal it skips. When it's done it joins using CRLF and writes it all back to the file.

 

Now you could use that logic to look for differences. For the deleted files you could test back the other way but there is a much cooler trick I found. Simply delete common values as you find matches. EG if you had two arrays A and B you could test the values from A against values in B. If your value in A finds a match in B delete the values in A and B. When you are done what is left in A are new files and what's left in B are deleted file.

Link to comment
Share on other sites

Cory,

 

Hello. I hope you are well.

 

Can you clarify something for me? With create, rename or delete file activation trigger, How can you make a folder and lots of subfolders dynamic in that whatever happens in any of the folders or subfolders, the macro can catch it?

 

What I mean is, if I move a file to a different subfolder, if I delete a file, if I rename a file, if I create a file, etc. Obviously there would be a different subroutine for each of these, but what would be simple examples for each?

 

I would think there would be 1 master text file and when the trigger is activated, a repeat with folder would compare them, but I would assume that the Repeat with Folder would be compared to the text file AS a whole variable.

 

The question is, for example, how can I get the macro to nail down that I moved a file? If I deleted a file, would you check the recycle bin file to indicate that it was deleted? How about when a file is dragged in from outside the folder and subfolder structure and into the folder/subfolder? In other words, how can the macro tell me exactly what it did?

 

I guess it would be something that would take time to create? Of course it would, but I am not asking for anyone to make a macro for me rather some keen insight on how to approach this.

 

I am itching to buy this, but I need some justification in my mind to do it.

 

Thanks!

 

Pat

Link to comment
Share on other sites

It would get complicated to do all you propose.

...............................................

But parts I could see being pretty simple.

 

First off the folder activation has an option to monitor subfolders as well. I envision one macro that would simply monitor folder and file changes and launch other macros. However that would depend on exactly what you were trying to do. But I would imagine maintaining a large list of folders and files like I described in one big text file. You would have to do the "Repeat with Folder" twice, once to pick up folders and the other to pick up files. But then simply look for the differences and report or act on however you please.

 

Now doing things like detecting folder moves and such would require some more advanced logic I think. But then again in most cases only one folder would move at a time so maybe not too hard. I could see the macro returning two values in a simple folder move. From its perspective one would delete and the other would be created. Just compare the path backwards one character at a time until they don't match, deleting each as you go, and you could say folder A moved from here to here. But if it had subfolders and all that it would take some more thinking.

Link to comment
Share on other sites

I don't recommend a binary (splitting) search unless the file list is really huge. It is way faster on large directories but even at that the speed is most likely not a concern.........

 

I tried it before responding and it depends hugely on the PC. My old PC does about 500 filenames per sec*. On my newer PC it will do 10,000 almost instantly. If the total time is insignificant it's not an issue.

 

I've tried folder comparisons and filename searches through multiple files/folders before. They can take 40mins. That's why for significant searches it's often easier to use something like Directory Opus. I have hybrid search macros that do the donkey work with Opus and the final search and listing with ME. Opus is not always quicker - converting a folder of filenames to a text file listing takes significant time, about the same as ME.

 

* this includes counting each repeat, plus an If to exit at a predetermined number

Edited by JohnS
Link to comment
Share on other sites

NP.

..........................................................

Suggestion: Use the "Reply" button in the messages instead of the "Add Reply" button at the bottom. For those of us that use the outline view it groups the messages into threads. And if you haven't yet you might check out the outline view.

Link to comment
Share on other sites

NP.

..........................................................

Suggestion: Use the "Reply" button in the messages instead of the "Add Reply" button at the bottom. For those of us that use the outline view it groups the messages into threads. And if you haven't yet you might check out the outline view.

 

If I'm replying generally to the main thread I use the Reply button at the bottom. If I'm replying specifically to someone, I use the button on their message. Perhaps there are too many "side discussions"?

Link to comment
Share on other sites

Hello Everyone.

 

I am still looking for a simple example of how this Activation Trigger works. I am befuddled!!!! Can someone from Insight chime in? I am itching to buy this, but I just need a real short example of how this works since there are no samples in the new Help file. A short example for each choice would help me a lot. I think the new version is so neat and fun. I might be able to make a career out of this!

 

Someone? Anyone?

 

Pat

Link to comment
Share on other sites

Thanks John,

 

That's awfully simple. I hope I didn't come across as a simpleton! Actually what I am looking for is something a smidge more difficult. For example, when a file is has been moved, how do proceed with that? I want to know the exact file or files that have been moved from what folder to what folder? I know this was mentioned above somewhat, but I am trying to see how fast ME is when it comes to one IF NOT all of those activations working together in tandem.

 

Since this is a new Activation trigger, what I am looking for is how would someone proceed with monitoring if a file has been moved. Does this mean that you would check to see if the file/folder size changes? If so, what do you use in the script? Would you compare text files using a Repeat with Folder and create a massive text file and create another massive text file to compare it to? If so, how would you do it when a file has moved? How fast is it when it comes to 40,000 files, for example, and hundreds of folders?

 

These kinds of things would be helpful. You know I think it would be pretty much a boilerplate macro to just create something that would something like this. It's just not computing right now.

 

Pat

Link to comment
Share on other sites

Back in my post #2 I indicated that you could use something like the mex I posted to flag the event and use "something else" for the specifics. If you want to know what has changed, and particularly where it went, it is not a simple issue. If I were doing this, I would flag the event in ME using the mex file then in Directory Opus I would do a search for *.* and look for files changed within a recent time period. My PC is too slow to monitor all files on the PC with ME. You should check out a current, similar thread in the ME3 forum (which is yours I guess!).

Link to comment
Share on other sites

Pat I've explained this to you in my previous responses. I don't know what more I could do besides actually write it for you. And you have already made it clear you don't want to hire me. And you want examples of activations so you can understand how they work? How about you just do an experiment yourself? That's how I learned 90% of this. Don't worry, you won't reformat your hard disk if you try a simple macro with an activation that pops up a display box. And I don't understand how you can't understand how these activations work. Pop open help and it will tell you that the "Create Rename or Delete a File" option means "The macro activates when a file in the selected folder is either created, renamed or deleted." I mean these all seem pretty clear to me. Perhaps you could tell us which one of the activations you don't understand?

 

Also if you read my other posts like "Some speed tests with arrays" I have even quantified how fast it is. EG 25k folders in one second. Seems pretty quick to me.

 

I just get the feeling you don't value my contributions so I think I'll focus my efforts on other members of the forum for a while.

Link to comment
Share on other sites

Ok. That's it! It's arrays I don't understand and being new to the new version, the new way variables are created has me all confused. I don't want anyone to write anything complex for me. I worked with ME pretty well.

 

For some reason, and maybe it's because I am going back to school(and studying hard), it's not forming in my mind. I just can't grasp it right now.That's all really. I am not trying to get under anyone's skin, I just don't get the concept. Must be dain bramage!!!!

 

I will google arrays.

 

Sincerely,

 

Pat

Link to comment
Share on other sites

Ha ha ha. You don't even realize you know what arrays are!

..........................................

No need to look it up buddy. The 4 variables you were given and used in ME3 were arrays! You're half way there! In MEP the best improvement was that we could have properly named variables like %State% and %Zip%. But these only hold one value. But if I wanted to define an array for your folders I would create one called... let me think.... Oh, I got it, %Folders%! (So much better that %T[72]%) Except when I define it I'm going to tell MEP it will have 100,000 elements. That comparable to the 99 you were fixed with in ME3. So to load all the folder names I would simply repeat with folder and in that repeat increment an integer %Counter%. EG if C:\Windows is the 6th folder in the root the value of %Folder[6]% might be "c:\windows". Now in the Repeat with Folder command I would tell it the variable to save this folder name in would be %Folder[%Counter%]%. See? I just put a variable in the index number part.

 

I made you a simple sample and it's attached.

 

Now what I do is create arrays to hold all these folder names then do logical comparisons. So I might create a repeat with that counter however many times the array is deep (Keep track of that) and check each one to see if equals the other.

 

One part you might want to learn in order to do what I want suggested earlier is to check out the split and join commands so you can cache the array in a file and read it back in later. You could use the pipe character for instance "|".

 

I hope that helps you understand at least that component of all this. Because you're absolutely right if you done' know what I'm talking about when speaking of arrays this would all be very confusing indeed!

Array_sample_for_Pat.mex

Link to comment
Share on other sites

Ok. That's it! It's arrays I don't understand and being new to the new version, the new way variables are created has me all confused.

For some reason, and maybe it's because I am going back to school(and studying hard), it's not forming in my mind. I just can't grasp it right now.That's all really. I am not trying to get under anyone's skin, I just don't get the concept. Must be dain bramage!!!!

I will google arrays.

Go stand in front of a bookcase containing some books.

Look along, say, the 3rd shelf. Let's assume it contains 10 books.

The 6th book in this shelf contains 200 pages.

The 40th page in this book contains 750 words.

Each object is a single-dimension array, i.e. Shelves, Books, Pages.

Many computer languages (but not MEP) allow you to store a single multi-dimensional array, so that a reference to MyArray(3 (shelf), 6 (book), 40 (page)) would return 750 (number of words).

Arrays are easy to navigate:

for i = 1 to 10
 ... shelf processing
 for j = 1 to 100
... book processing
for k = 1 to 1000
  ... page processing
next k
 next j
next i

which assumes up to 10 shelves in my single bookcase, up to 100 books per shelf, and up to 1000 pages per book.

 

Does that help, or have I simply made things worse?

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...