Jump to content
Macro Express Forums

Escalate 'selection' of a folder


Recommended Posts

I can get a macro to 'select' a folder whose name I want to change; as my snip shows, the selection is not the usual highlighting which makes it susceptible to right-click, but only makes it encased in a rectangle. How do I convert that to full selection, so I can right-click on it ?

Capture.JPG

Link to comment
Share on other sites

The rectangle means the folder has focus, but is not selected. Ctrl + spacebar toggles between selection and focus.

 

PS: If you don't need to toggle between the two states (and you probably don't), pressing the space bar will select the focused folder.

 

PPS: No need to right-click to rename. Once the folder is selected, press F2 to rename.

Link to comment
Share on other sites

I did not get notification of your reply so spent much time experimenting and found your first P.S. to be the case.

 

The aim of the macro is to select the folder called Data, change its name to a date, and then move it into a folder called Data Old.

 

I did a work around using the mouse location and clicks and got surprisingly far, but Macro Express never fails to trip me up somehow.

I include the full macro text - which works (reliably) up until the last stage (Pasting) where it surprises me with an outlandish claim shown in the attachment :

 

 

Pasting.JPG.9e8e3e06b3c48e1011ae0b6cfaf4b96e.JPG

 

I might observe that the last step somehow causes the 'name-changed-folder' to become selected again; and so it must look to Macro Express that I am trying to paste it into itself.

 

<LOCK PLAYER Wait="TRUE"/>
<COMMENT Value="Open A:\\"/>
<OPEN FOLDER Path="A:\\"/>
<WINDOW ACTIVATE Title="A:\\" Exact_Match="FALSE" Wildcards="FALSE" _IGNORE="0x0006"/>
<DELAY Flags="\x01" Time="0.5"/>
<COMMENT Value="7 TABs to select \\Data\\"/>
<REPEAT START Start="1" Step="1" Count="7" Save="FALSE"/>
<TEXT TYPE Action="0" Text="<TAB>"/>
<DELAY Flags="\x01" Time="1"/>
<END REPEAT/>
<COMMENT Value="Space to change from selection to Focus"/>
<TEXT TYPE Action="0" Text="<SPACE>"/>
<DELAY Flags="\x01" Time="1"/>
<COMMENT Value="Move the mouse over the word Data"/>
<MOUSE MOVE Option="\x02" X="250" Y="225" _PROMPT="0x000A"/>
<DELAY Flags="\x01" Time="1"/>
<COMMENT Value="Left-click to select text"/>
<MOUSE LEFT CLICK/>
<DELAY Flags="\x01" Time="2"/>
<DATE/TIME Format="20yymmdd" Flags="\x30" Date="5/9/2021 1:30:28 PM" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="1" IsDateVar="FALSE"/>
<COMMENT Value="Enter to confirm"/>
<TEXT TYPE Action="0" Text="<ENTER>"/>
<DELAY Flags="\x01" Time="2"/>
<COMMENT Value="Right-click to expose Cut"/>
<MOUSE RIGHT CLICK/>
<DELAY Flags="\x01" Time="2"/>
<COMMENT Value="Down arrow 6 times to select CUT"/>
<REPEAT START Start="1" Step="1" Count="6" Save="FALSE"/>
<TEXT TYPE Action="0" Text="<ARROW DOWN>"/>
<DELAY Flags="\x01" Time="0.5"/>
<END REPEAT/>
<COMMENT Value="Enter to effect cutting"/>
<TEXT TYPE Action="0" Text="<ENTER>"/>
<DELAY Flags="\x01" Time="0.5"/>
<COMMENT Value="Down arrow to select 'data old'"/>
<TEXT TYPE Action="0" Text="<ARROW DOWN>"/>
<DELAY Flags="\x01" Time="0.5"/>
<COMMENT Value="Right-click to expose Paste"/>
<MOUSE RIGHT CLICK/>
<DELAY Flags="\x01" Time="2"/>
<COMMENT Value="Down arrow 8 times to select Paste"/>
<REPEAT START Start="1" Step="1" Count="8" Save="FALSE"/>
<TEXT TYPE Action="0" Text="<ARROW DOWN>"/>
<DELAY Flags="\x01" Time="0.5"/>
<END REPEAT/>
<COMMENT Value="Enter to effect pasting"/>
<TEXT TYPE Action="0" Text="<ENTER>"/>
<DELAY Flags="\x01" Time="0.5"/>
<MACRO STOP/>

 

Link to comment
Share on other sites

Might it be possible to rename and move using Macro Express commands? Manipulating a user interface to perform these tasks might get flaky!

 

Maybe something like this untested example?

 

Date/Time: Set %Date% to the current date/time using "YYYY-MM-dd" as the format

Rename File/Files: "c:\tmp\Data" to "c:\tmp\%Date%"
Move File/Files: "c:\tmp\%Date%" to "c:\DataOld\%Date%"

 

Link to comment
Share on other sites

Looks so much easier !

 

 

I could not create a new macro for some reason, so copied an existing one and disembowelled it, by deleting its contents and replacing it with your code.

I modified where your guesses did not match my system.

It failed.

I guessed that time delays may be required between the steps.

I'm working on putting those last steps into proper format.

 

Link to comment
Share on other sites

Much simpler but mush less effect than my attempt.

 

<LOCK PLAYER Wait="TRUE"/>
<TEXT TYPE Action="0" Text="Date/Time: Set %Date% to the current date/time using \"YYYY-MM-dd\" as the format\r\n\r\n"/>
<DELAY Flags="\x01" Time="1"/>
<RENAME FILE/FILES Source="\"a:\\Data\"" Dest="\"a:\\%Date%\"" Progress="FALSE" Recurse="FALSE"/>
<DELAY Flags="\x01" Time="1"/>
<MOVE FILE/FILES Source="\"a:\\%Date%\"" Dest="\"a:\\DataOld\\%Date%\"" Progress="FALSE" Recurse="FALSE"/>
<DELAY Flags="\x01" Time="5"/>
<MACRO STOP/>

 

Could it be that there is an excess of " ?
I'm also surprised to see double slashes...

 

Link to comment
Share on other sites

I don't think the lack of delays is the problem, although short delays may be needed in the end. Here are the issues that are preventing the macro from working that I've spotted:

 

Line 2: This is not a statement that sets a variable. It's a statement to type out text. Delete the line, and recreate it from scratch: Variables > Date/Time.

 

Lines 4 and 6: There are quote marks around the file names that shouldn't be there. Edit the lines and delete the quote marks from the files names.

 

In other words, change:

 

"a:\Data"

 

to

 

a:\Data

 

Also, these changes will be easier to do with "Direct Editor" mode toggled OFF. Not sure if this is what is what is happening, but thought I'd mention it. This setting is in the "View" menu in the Script Editor.

Link to comment
Share on other sites

Direct Editor was already NOT ticked.

 

My code now is

<DATE/TIME Format="yyyymmdd" Flags="\x30" Date="5/9/2021 11:52:04 PM" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="1" IsDateVar="FALSE"/>
<DELAY Flags="\x01" Time="1"/>
<RENAME FILE/FILES Source="a:\\Data" Dest="a:\\%Date%" Progress="FALSE" Recurse="FALSE"/>
<DELAY Flags="\x01" Time="1"/>
<MOVE FILE/FILES Source="a:\\%Date%" Dest="a:\\DataOld\\%Date%" Progress="FALSE" Recurse="FALSE"/>
<DELAY Flags="\x01" Time="1"/>
<MACRO STOP/>

 

But it is still ineffective.

 

 

 

Link to comment
Share on other sites

The variable %Date% in Line 1 is not defined. Edit the instruction, go to the "Operations" tab, and choose to store the date as text variable %Date%.

 

Line 3 renames a file called "a:\Data". But is that really the name of the file? If the file name has an extension, you must include it in the file name: Data.txt, Data.doc, Data.xml, or whatever.

Link to comment
Share on other sites

You are so on the right track!

 

Change the value in the drop-down list from:

 

"Type the date/time stamp out"

 

to

 

"Store the date/time stamp as a variable"

 

The item currently selected outputs the date as though you were typing it. The item you want stores the date. By storing it, you can output the date twice: first, when you rename the file, and second, when you move the file.

Link to comment
Share on other sites

There's a lot to learn of while getting comfortable with Macro Express. Your learning curve is typical!

 

The second field from the top is currently blank. Macro Express needs to know the name of the variable that will store the date. The variable name I suggested in my original response was %Date%. 

 

So in the second field from the top, type in:

 

%Date%

 

Alternatively, click the "Variable" button next to the field. If you navigate around enough, you may find it there. Or you may be forced to create a new text variable. Overall, through, I think it's easier just to type %Date% in the field.

 

If the variable %Date% doesn't exist, Macro Express will prompt you to create it when you save the macro.

Link to comment
Share on other sites

I'm not sure how to copy an entire folder. But it's possble to copy the content of an entire folder:

 

Copy File/Files: "C:\Users\Alan\Documents\Test\*.*" to "C:\Users\Alan\Documents\Test\Testing\"


<COPY FILE/FILES Source="C:\\Users\\Alan\\Documents\\Test\\*.*" Dest="C:\\Users\\Alan\\Documents\\Test\\Testing\\" Progress="TRUE" Recurse="FALSE"/>

 

Star-dot-star is a wildcard that represents all files contained in folder C:\Users\Alan\Documents\Test

 

If you only need to copy a single file, you can do the following, which copies the file called "File.txt" into the "Testing" sub-folder.

 

Copy File/Files: "C:\Users\Alan\Documents\Test\File.txt" to "C:\Users\Alan\Documents\Test\Testing\"

<COPY FILE/FILES Source="C:\\Users\\Alan\\Documents\\Test\\File.txt" Dest="C:\\Users\\Alan\\Documents\\Test\\Testing\\" Progress="TRUE" Recurse="FALSE"/>

 

Link to comment
Share on other sites

Sebastian,

 

As was mentioned above you could use Macro Express commands to copy all files and folders in the Data folder to another folder. This example copies the files and folders from the folder Data to a folder that contains the date, e.g. E:\Data --> E:\Data09092021 while leaving the original Data folder intact.

 

Variable Set String %SourceDir% to "E:\Data"
Variable Set From File date
Variable Set String %DestinationDir% to "E:\Data%FolderDay%%FolderMonth%%FolderYear%"
Copy File/Files: "%SourceDir%\*.*" to "%DestinationDir%"

 

<VARIABLE SET STRING Option="\x00" Destination="%SourceDir%" Value="E:\\Data" NoEmbeddedVars="FALSE"/>
<VARIABLE SET FROM FILE Filename="%SourceDir%" Option="\x00" Date="\x01" Month="%FolderMonth%" Day="%FolderDay%" Year="%FolderYear%" Flags="\x07"/>
<VARIABLE SET STRING Option="\x00" Destination="%DestinationDir%" Value="E:\\Data%FolderDay%%FolderMonth%%FolderYear%" NoEmbeddedVars="FALSE"/>
<COPY FILE/FILES Source="%SourceDir%\\*.*" Dest="%DestinationDir%" Progress="TRUE" Recurse="TRUE"/>

 

If you want to rename the Data folder you can use the following. This example moves the files and folders from the folder Data to a folder that contains the date, e.g. E:\Data --> E:\Data09092021 . The original folder E:\Data is removed.

 

Variable Set String %SourceDir% to "E:\Data"
Variable Set From File date
Variable Set String %DestinationDir% to "E:\Data%FolderDay%%FolderMonth%%FolderYear%"
Rename File/Files: "%SourceDir%" to "%DestinationDir%"

 

<VARIABLE SET STRING Option="\x00" Destination="%SourceDir%" Value="E:\\Data" NoEmbeddedVars="FALSE"/>
<VARIABLE SET FROM FILE Filename="%SourceDir%" Option="\x00" Date="\x01" Month="%FolderMonth%" Day="%FolderDay%" Year="%FolderYear%" Flags="\x07"/>
<VARIABLE SET STRING Option="\x00" Destination="%DestinationDir%" Value="E:\\Data%FolderDay%%FolderMonth%%FolderYear%" NoEmbeddedVars="FALSE"/>
<RENAME FILE/FILES Source="%SourceDir%" Dest="%DestinationDir%" Progress="FALSE" Recurse="FALSE"/>

 

NOTE: the folder names cannot have a trailing "\" or contain "\*.*"  When they do the copy or rename does not work correctly.

 

I used the folder's modified date to create a destination folder like E:\Data09092021. I did not include hours and minutes in the destination folder name. You can easily add these. You could also choose to use the date/time when the macro runs, similar to what you have above.

Link to comment
Share on other sites

Since I thought I had come to the end of the road in Macro Express, and was going to run the macro from a batchfile anyway, I've explored doing the data copy by batch file code, and with help from someone in the Microsoft Community, I've been able to achieve that with one very simple line of code, which HAS to be preferable to the more complex code suggested in the previous post. Thank you anyway.

Link to comment
Share on other sites

Quote

I've been able to achieve that with one very simple line of code, which HAS to be preferable to the more complex code suggested in the previous post.

 

Hi Sebastian,

 

My impression is that the Macro Express aficionados who haunt this forum gravitate to Macro Express not because it's a super-efficient, leading-edge programming environment, but because it's a useful, interesting, and quirky tool that non-programmers can sink their teeth into and get excellent results.

 

Many if not most people who are "into" Macro Express, I would guess, understand, accept, and even embrace its limitations. Macro Express is almost always my first choice when there's a task I want to automate, simplify, or improve. That's because I can often create working prototypes in minutes.

 

But I don't use Macro Express for everything. For some tasks, other tools are clearly better. For example, I once automated a task using AutoHotkey, and using Macro Express. The AutoHotkey version runs in the blink of an eye, while the Macro Express version runs in slow motion. Although the AutoHotkey version is more practical, I sometimes opt to use the Macro Express version because I'm proud that I was able to make it work, despite Macro Express's constraints.

 

The beauty of Macro Express, for me, is that its constraints spark creativity.

Link to comment
Share on other sites

"its constraints spark creativity. " amply demonstrated by complex code that can be replaced by one line in a batch file.

 

Incidentally, I've used up all the available keys with Left-Win and Right-Win for text string entries. I think that has exhausted my potential use of Autohotkeys.

Link to comment
Share on other sites

12 hours ago, Sebastian42 said:

Since I thought I had come to the end of the road in Macro Express, and was going to run the macro from a batchfile anyway, I've explored doing the data copy by batch file code, and with help from someone in the Microsoft Community, I've been able to achieve that with one very simple line of code, which HAS to be preferable to the more complex code suggested in the previous post.

Sometimes ME can dynamically build (then run) the simple line of code, or the whole batch file.  That's not needed if the batch commands do exactly the same thing every time, but it is useful if the batch does the same "function" but with variable data.  For example, macro 1 runs a standard directory list with output to a text file; macro 2 reads back the text, analyzes data file sizes, builds a different "copy" command batch file for each data file based on how big the file is today and whether the backup should be compressed or not; macro 3 runs the copies a few at a time to avoid overloading the server.  (That's a real application, as you may have guessed.)

 

In other words, macros can utilize the simple and efficient batch commands, while applying logic and intelligence that otherwise would be lacking. 

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