Jump to content
Macro Express Forums

Monitor download file


Recommended Posts

I have just downloaded and am wanting to create a macro that will monitor a download file.

 

I am using the Dir Events on the folder. I then used the move file.

 

The problem I have is if its a large file it tries to copy it before its ready. I then found the "wait for file to be ready option" but I don't know how to get the exe file name for the file or files being downloaded into the the download folder.

 

I found on the forum that using the "Repeat with folder" can get a list of files but I don't know how to then filter out the relevant extension file for example *.exe

 

I have done a search of the forum but have not found what I needed.

Link to comment
Share on other sites

Ok I think I may have cracked this I was just wondering if someone could check it over and tell me if there is a better way to do it.

 

<REPEAT WITH FOLDER Path="C:\\Users\\user\\Downloads\\" OnlyFiles="TRUE" Destination="%Exe Name%" FullPath="TRUE" ProcSubfolders="FALSE"/>

<VARIABLE SET FROM FILE Filename="%Exe Name%" Option="\x01" Extension="%file_extension%" Expand="FALSE" Flags="\x08"/>

<IF VARIABLE Variable="%file_extension%" Condition="\x00" Value=".exe" IgnoreCase="FALSE"/>

<WAIT FOR FILE TO BE READY Filename="%Exe Name%" Time="10" Indefinite="TRUE" Hours="0" Minutes="0" Seconds="0"/>

<MOVE FILE/FILES Source="%Exe Name%" Dest="C:\\Users\\user\\Downloads\\EXE Files\\" Progress="FALSE" Recurse="FALSE"/>

<END IF/>

<END REPEAT/>

Link to comment
Share on other sites

Ok I think I may have cracked this I was just wondering if someone could check it over and tell me if there is a better way to do it.

Your code looks and works fine, though I would change the "file must be ready for" of the Wait for File command to a maximum of 2 seconds instead of 10.

Your code contains these assumptions:

- only .exe files will be moved to the target folder

- all .exe files will be moved to the target folder

- the target folder will not already have [a] file of the same name as the one you want to move

 

To be pedantic, I'd prefer to see your variable names without spaces, and of a standard format. In your code you use %Exe Name% and %file_extension%, while I would use %tExeName% and %tFileExtension%, where the initial t indicates a text variable. This isn't at all important in a macro this short and simple; but in longer macros, consistent variable names can aid in understanding and debugging.

Link to comment
Share on other sites

  • 2 weeks later...
Paul, why don't you like spaces in variable names?

Because, generically speaking, it's unprofessional! Most languages don't permit spaces in variable names - in fact I can't think of a single one, although I'm sure someone can correct me on this! I much prefer camel case, e.g. FirstName, StreetAddress, VariableName. Some languages permit spaces in some circumstances, but you then have to add additional characters to make it work, e.g. in Sql Server I can have column names with spaces, but then I must say:

SELECT [First Name]

instead of

SELECT FirstName

I find the second syntax more readable and it requires less typing.

In writing, spaces are used to separate words. I want my variable names each to be apparent as a single word, because each of them represents a single thing.

When naming files, I also avoid spaces because I can then refer to the file without quotation marks (though of course the path name often does contan one or more spaces). FWIW, software often adds stuff to the registry to enable right-click context menu items to address the selected file or files. So right-click on a text file and you can then open it with Notepad. But the registry entry is often (or even usually?) wrong because it references the selected file in its registry entry by %1 instead of "%1". Without those quote marks, the command won't work if the filename contains a space!

Link to comment
Share on other sites

So you have no reason to do it in MEP other than it's habit;-) Personally I find it easier to read with spaces. Camel Case! Ha, I didn't know it had a name. Personally I think it's a credit to ISS that they don't follow that arcane rule. Same for me are languages that are case sensitive. Also I don't see the need for a prefix character to indicate variable type. Usually the context tells the tale and if not just open the Variables tab or group when using the Select Variables dialog. I don't know, I've just never had any confusion on the matter. Although in some cases I want an integer and a string named the same. Like Client ID in both text and integer for some reason. But that's rare. Leaving off the prefix again makes things more readable. I guess to me it's like how I still to this day find old accountants who TYPE EVERYTHING IN CAPS. ALWAYS. EVEN EMAIL. Hello! you're not on that ancient Digital mainframe anymore that didn't support mixed case. But when I asked them why they do that there answer always is much like yours and something to the effect of "That's the way it's supposed to be done" without ever having a valid reason and ignoring how technological advances change the 'proper way'. But at least it supports both methods. I'm just a little defensive when you characterize my method as unprofessional.

Link to comment
Share on other sites

Same for me are languages that are case sensitive.

Agreed.

Also I don't see the need for a prefix character to indicate variable type. Usually the context tells the tale and if not just open the Variables tab or group when using the Select Variables dialog.

But then you have to read and understand the context, which requires time and effort. And opening the Variables tab doesn't work well when the macro is printed.

I guess to me it's like how I still to this day find old accountants who TYPE EVERYTHING IN CAPS. ALWAYS. EVEN EMAIL. Hello! you're not on that ancient Digital mainframe anymore that didn't support mixed case. But when I asked them why they do that there answer always is much like yours and something to the effect of "That's the way it's supposed to be done" without ever having a valid reason and ignoring how technological advances change the 'proper way'.

I can't see any similarities here. Typing everything in caps makes the text considerably less readable. And I believe I advanced several valid reasons for my approach.

I'm just a little defensive when you characterize my method as unprofessional.

As I recall, you simply asked me why I don't like spaces in variable names. And I told you. If you then want to feel defensive because you infer that I am criticizing you, then feel free. But when I gave you my answer, it was my answer; I was speaking for myself; I wasn't trying to convince you to change your practices; in truth, I wasn't thinking about you at all, and I certainly wasn't thinking about your methods. It's not only about you, you know! :rolleyes:

 

But I must say I don't know any programmer-type people who would ever want to include spaces in variable names. And in the enormous sample of such people I have polled , those who would make such a choice number less than 1.

Link to comment
Share on other sites

But I must say I don't know any programmer-type people who would ever want to include spaces in variable names. And in the enormous sample of such people I have polled , those who would make such a choice number less than 1.
No offense taken, I'm not riled. Just challenging yor reasons:-) But the argument 'because programmers do it' is flawed as most of those programmer are in an environment that doesn't allow spaces so of course they will not be in the habit. I write macros in MEP. Also just because a lot of people do something doesn't satisfy me as a valid reason to follow suit. Millions of people play the lottery but that doesn't mean it's a sound financial investment;-)
Link to comment
Share on other sites

But the argument 'because programmers do it' is flawed as most of those programmer are in an environment that doesn't allow spaces so of course they will not be in the habit. I write macros in MEP. Also just because a lot of people do something doesn't satisfy me as a valid reason to follow suit. Millions of people play the lottery but that doesn't mean it's a sound financial investment;-)

I disagree. The argument "because programmers do it" is not at all like people who buy lottery tickets. It's much more analagous to driving with a professional car driver, who will do things that we amateurs might question, but which we generally would do well to imitate.

Link to comment
Share on other sites

OT but what the heck. I've migrated over time to leaving out spaces in variable and folder names, mostly. MS did not help much by having paths like "Program Files" and "Documents and Settings" so some of the time you still have to figure out if a "%20" or path in quotes are needed. Long-term, variables are likely to become more and more literal to accommodate the general public. As I've mentioned a few times in other threads, any sort of syntax is counter-productive from the human perspective. Machine code is the pits; verbally telling your computer what to do/needs to be done in any language or dialect is almost as good as it gets. We've moved on; who cares today about machine code other than a few people in the industry?

Link to comment
Share on other sites

verbally telling your computer what to do/needs to be done in any language or dialect is almost as good as it gets. We've moved on; who cares today about machine code other than a few people in the industry?

Who was talking about machine code? Not I and not Cory. Another rant perhaps?

Let me tell you a story James Martin used in his world-famous discourses in the 1980's.

At the entrance of a building site is a sign that reads "Hard hats must be worn". People entering the site therefore obtain a hard hat and wear it.

At the top of an escalator leading to underground trains is a notice that reads "Dogs must be carried". Does that mean it's someone's job to hand out dogs to those unfortunate people who don't have one?

This illustrates the vitual impossibility of "verbally telling your computer what to do".

Link to comment
Share on other sites

I disagree. The argument "because programmers do it" is not at all like people who buy lottery tickets. It's much more analagous to driving with a professional car driver, who will do things that we amateurs might question, but which we generally would do well to imitate.
OK if you don't like my analogy let's use yours. I agree that there are several things we could learn to do better in everyday driving from race car drivers. But race car drivers also wear full fire resistant protective clothing. In a race car this is a rule and prudent. In a passenger car this is not required and unnecessary. So too in VB I don't (can't) use spaces but in MEP I can and will until I find a reason not to. My only challenge to you was to give me a technical reason why it's a bad idea in MEP. So far I haven't heard one that satisfies me. But I'm keeping an open mind. Remember how we had the debate back in the beta days about dialog boxes which didn't force us to enter the percent signs around variable names? At first it didn't seem like there was any need to when allowed but later I found that if one wants to use find and replaces it could really mess with you. So now I use percent signs even when I'm not required to. I was looking for a reason like that from you. So far I can't think of one.
Link to comment
Share on other sites

My only challenge to you was to give me a technical reason why it's a bad idea in MEP. So far I haven't heard one that satisfies me. But I'm keeping an open mind.

But there's more to life than technical reasons! :rolleyes:

I think my best reason is

In writing, spaces are used to separate words. I want my variable names each to be apparent as a single word, because each of them represents a single thing.

For me, "First Name" should represent 2 things, not one. I find FirstName easier on the eye, but your prefererece is opposite to mine. In MEP I don't think it's a matter of technical reasons for preferring one method over another, e.g. variable names, IF vs CASE, etc., but more a matter of taste. And my taste is clearly superior to yours - just stop worrying about it! :lol::rolleyes:

Link to comment
Share on other sites

I like the quote about spaces separating words as I think it proves my point. The problem is that a thing (object) in the real world if often represented by more than one word. EG The United States of America.

Yeah I'm not worried about it. I was just hoping to learn something from someone far more experienced than I. And I guess I did learn something and that it that there's nothing wrong with using spaces in MEP variables! ;-) I'm glad you're comfortable in your superiority as I am now too. Good thing about MEP is that it supports either 'best' practice. But all joking aside if you ever do think of another reason not to use spaces I would love to hear it.

I will admit however you do have me reconsidering adding a char for variables type though. But I'm thinking maybe at the end. I do like grouping my variables alphabetically sometimes. Like a source TSV file that contains strings and integers I might want to have them all "Source" so they all group together. But it would be cool then to have "Source CID S" and "Source CID I" next to each other. Hmmm...

Link to comment
Share on other sites

I will admit however you do have me reconsidering adding a char for variables type though. But I'm thinking maybe at the end. I do like grouping my variables alphabetically sometimes. Like a source TSV file that contains strings and integers I might want to have them all "Source" so they all group together. But it would be cool then to have "Source CID S" and "Source CID I" next to each other. Hmmm...

Yes, I originally used I for Integer variables. But since MEP uses N, I've switched to that. So, I use t (text), n (integer), d (decimal), b (boolean), c (control), h (handle) and I can't decide what to use for dates (whether dt, or a). And I've not used Large Integers - I suppose that should be N in contrast to n!!

Link to comment
Share on other sites

Yes, I originally used I for Integer variables. But since MEP uses N, I've switched to that. So, I use t (text), n (integer), d (decimal), b (boolean), c (control), h (handle) and I can't decide what to use for dates (whether dt, or a). And I've not used Large Integers - I suppose that should be N in contrast to n!!
I like N since I've always used that in science and math classes. Interesting you like T. I was thinking the other day that it's a misnomer to call text string. Any group of characters can be a string. But then again one can have a 'string' of binary data as well. For instance I can use string vars to process a BMP file. I can't resolve this one. But in most computer languages I see this variable type called "String". Should we not emulate real programmers? ;-) Going thru the list of vars in the help file I think it should be fairly intuitive.
  • T Text (could be S alternatively)
  • N Integer
  • L Large integer
  • D Decimal
  • C Control
  • T Date/Time. (to me it's all time)
  • B Boolean
  • H Handle

I think I'll adopt this list.

Link to comment
Share on other sites

I like N since I've always used that in science and math classes. Interesting you like T. I was thinking the other day that it's a misnomer to call text string. Any group of characters can be a string. But then again one can have a 'string' of binary data as well. For instance I can use string vars to process a BMP file. I can't resolve this one. But in most computer languages I see this variable type called "String". Should we not emulate real programmers? ;-) Going thru the list of vars in the help file I think it should be fairly intuitive.
  • T Text (could be S alternatively)
  • N Integer
  • L Large integer
  • D Decimal
  • C Control
  • T Date/Time. (to me it's all time)
  • B Boolean
  • H Handle

I think I'll adopt this list.

I use T for the same reason as I use N - because MEP does (though I use lower-case). You've got T twice in your list - was that intentional?

I do like your T for date/time though...

Link to comment
Share on other sites

Who was talking about machine code? Not I and not Cory. Another rant perhaps?

Just putting forward a more global view of the issue in programmers terms. The fact there is even a discussion about whether one should have a space or not in a variable says it all.

Let me tell you a story James Martin used in his world-famous discourses in the 1980's. This illustrates the vitual impossibility of "verbally telling your computer what to do".

Would that guy be related to the one at IBM in the 1940s who was alleged to have said "I think there is a world market for maybe five computers". A few years later some apparently deaf scientist at Bell invented the transistor. OK you weren't talking about IBM or transistors; let's call this one a rant.

Link to comment
Share on other sites

I use T for the same reason as I use N - because MEP does
Well I don't belkeive in using the defauly 99 element arrays and the first ting I do when creating a new macro is to delete them
You've got T twice in your list - was that intentional?
No, I'm an idiot. But that makes a good case for using S for strings!
Link to comment
Share on other sites

  • 2 weeks later...

Just putting forward a more global view of the issue in programmers terms. The fact there is even a discussion about whether one should have a space or not in a variable says it all.

 

Would that guy be related to the one at IBM in the 1940s who was alleged to have said "I think there is a world market for maybe five computers".

 

 

No! That was probably never actually said. It was attributed to Tom Watson, Chairman of IBM, but as you see here

http://en.wikipedia.org/wiki/Thomas_J._Watson

it appears to be a misquote or even a myth. Here's the beginning of that Wikipedia article:

 

"Famous misquote

 

Although Watson is well known for his alleged 1943 statement: "I think there is a world market for maybe five computers," there is scant evidence he made it. Author Kevin Maney tried to find the origin of the quote, but has been unable to locate any speeches or documents of Watson's that contain this, nor are the words present in any contemporary articles about IBM. [etc]"

 

James Martin was no relation. But he also worked at IBM, around 1963. I was a junior colleague at the next desk in our Chiswick, UK office, and vaguely recall his getting fired by our Branch Manager for losing an important airline account. I drafted a 'group petition' supporting him, but can't remember the conclusion! But I suppose if it had succedded and he'd stayed, then his subsequent rise to fame in his new career might never have happened.

 

--

Terry, East Grinstead, UK

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...
×
×
  • Create New...