Jump to content
Macro Express Forums

I Know It's Easy To Do It This Way, But...


patgenn123
 Share

Recommended Posts

I know it easy to just use "move file or files" to get a file to go into a folder, but how about automating it to go to that specific folder based on the first word of the file name matching the first word of folder name?

 

For example, what if I had a file named Excel Shortcut tips on my desktop.

What if I had a folder named "Excel" as a subfolder somewhere and I want it to go to that folder automatically.

 

I could be spending an endless amount of time creating "move file or files for every single file variation or I could make it easy.

 

Anybody have any ideas?

 

P

Link to comment
Share on other sites

I would use the Repeat with Folder command to get a list of folders. Then, as the repeat command loops, check each folder name to see if it contains 'excel' or whatever portion of the folder name is consistent. Once you get the folder name you can Break out of the repeat loop.

 

The Repeat with Folder command will put the name of the folders in a variable. You can then use the variable containing the folder name in the Move File or Files command.

Link to comment
Share on other sites

Kevin,

 

Please pardon my question if it seems to obvious since I lack a lot of computer knowledge.

 

I know how to do the repeat with folder, but I do NOT know the other steps.

 

How do I find the word "Excel" in the repeat folder loop?

What does it need to compare itself to? Obviously, the file name "excel".

How do I find the word "Excel" in the filename and isolate it and put it into a variable?

Doesn't that mean I need to set focus on the excel file first, loop it, and then compare to the folders by looping the folder also?

Or does it matter?

 

Pat

Link to comment
Share on other sites

Kevin,

 

What I ultimately want to do is this:

 

I have a folder that has files in it. All are different in name and type. Most of them have file names(1,2 or 3 words in the file name) and another folder that has subfolders.

 

Almost ALL of the files can be matched to these subfolders by the first name of the file. So really what i want to do is isolate the first name of the file, run a loop through them, isolate the corresponding subfolders(i guess by running a loop through the subfolders also?), match them together and send the files to the corresponding subfolder(s).

 

If in the future there are extra files stored in that folder, once they are renamed, they would go to the corresponding subfolder(s) the moment the name has been changed.

 

Seems like it might not be too hard? Or is it just a dream?

 

P

Link to comment
Share on other sites

Dear Moderators,

 

Thanks for all your help on this one. I really appreciate it.

 

If I was going to ask for you to write the whole program for me, I would pay you for it, but if I was just asking for some simple advice to point me in the right direction, it's a different story.

 

Thanks for the customer service.

 

Sincerely,

 

A grateful paying customer

Link to comment
Share on other sites

Hello!

 

Look, I know how frustrating it can be to have questions unanswered in a public forum. But remember, even the most simplest of questions can take a fair amount of time to answer. And I've learned over the years that there are simply times, for whatever reason, that questions remain unanswered. Believe me, it happens to ALL of us. And not just in this forum. It truly does.

 

I should reiterate at this point that this is our forum (Macros LLC / Professional Grade Macros). We support it. We sponsor it. It is NOT run by Insight Software Solutions. They are generous to take the time to read all the questions. And Kevin is great at answering them when others, such as myself, cannot. But they are, by no stretch of the imagination, responsible for what, or what does not, happen here.

 

The answer you need might not be as easy as you think it should be, but only because of your lack of programming experience. The answer to finding a string within another string is almost the same in any programming language. You need to to a sub string search, and in Macro Express that would be the Get Position of Text in a Text Variable command. There is your place to start.

 

The Macro Express of today, bears little resemblance to the Macro Express I started using 8 or 9 years ago. So, like, you, I'm learning something new almost everyday. Take your time. Experiment with the examples in the sample.mex file. Go through the tutorials. Read the online knowledge-base. Examine the help file. All of these things will help you. And after all, THAT is the most important thing.

Link to comment
Share on other sites

Here is a simple sketch of the macro you need

 

1) First you should use "Repeat with Folder" with

Return: Files

"Full File Path" selected

"Process Subfolders" ON

 

and choose the Main Folder wich contains the other subfolders: Excel, Word, etc.

 

This will, one by one, place on a variable (lets say T10) the Full File Path of all the files inside the Main Folder (including those wich are inside the subfolders Excel, Word and the others)

 

 

2) Now you need to get the File Name wich is placed at the last part of the Full Path.

 

Something like this should work:

 

<IVAR2:10:12:10><REP3:08:000007:000001:0001:0:01:\><NMVAR:09:10:0:0000001:0:0000000><TMVAR2:10:01:10:N10:9999:><ENDREP><TMVAR2:21:01:00:000:000:\>

 

T1 will contain the File Name now.

 

 

3) The next step is to retrieve the first word of the File-Name from T1 to T2

You should use the command "Get Position of Text in a Text Variable" as Joe said.

 

 

4) Finally, use Switches and Cases to read T2 and move the file.

 

Here is a base example:

 

<SWITCH:T2><CASE:excel><DOFILE:07:NN:%T10%>Main Folder Path\%T1%><ENDCASE><ENDSWITCH>

 

 

Hope this helps some.

Link to comment
Share on other sites

Joe and Strathos,

 

OK. Maybe I was premature about things and I apologize, but I plugged in the code and have no clue about what it means.

 

I want to understand this program and I did buy MACRO EXPRESS EXPLAINED, but no where would it give any sort of idea about the response by Strathos and how to structure this. MACRO EXPRESS EXPLAINED IS VERY GOOD, but there is no way I could have figured out what Strathos did to come up with the solution.

 

I still don't know.

 

I tried something myself.

 

Why doesn't this work?

 

Variable Set Integer %N1% to 0

Repeat with Folder

Variable Modify Integer: %N1% = %N1% + 1

Repeat End

If File Ready "%T1%*.pdf"

Move File or Files: "%T1%*.pdf"

End If

 

<IVAR2:01:01:0><REP3:07:000006:000001:0001:0:01:C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing><NMVAR:01:01:1:0000001:2:0000001><ENDREP><IFOTH:19:2:C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T1%*.pdf><DOFILE:07:NN:C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T1%*.pdf>C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T1%\%T1%*.pdf><ENDIF>

 

 

This "Repeat with folder" is putting the folder names into a variable and then putting the variable into the file name as Kevin explained to do, but it's not doing it and I must be missing a step. There is something I am missing in between.

 

If you separate the two parts in my macro, they work separately, but don't work together. For example, the second part(After the Repeat End Line) works with a prompt. If you prompt for a name, it brings everything together in all folders with a Change/Directory command line.

 

Can you help me with what I have done already?

 

Pat

Link to comment
Share on other sites

Pat,

 

The coding you provided does not do anything within the repeat folder. Try the following code. What this will do is activate if your file (T1) is ready... Once it is, it will repeat getting the "Full name" (T2) of each folder in that directory. Once your file contains the same name as the folder (T2 is found in T1... hence folder is named "Excel" and "Excel" is found in the file name), it will move the file to that folder. If not, it will repeat again until it either finds the folder, or runs out of them.

 

If File Ready "%T1%*.pdf"
 Repeat with Folder
   If Variable %T2% contains variable %T1%
     Move File or Files: "%T1%*.pdf"
     Break
   End If
 Repeat End
End If

 

 

<IFOTH:19:2:C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T1%*.pdf><REP3:07:000006:000001:0002:0:01:C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing><IFVAR2:4:01:7:T2><DOFILE:07:NN:C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T1%*.pdf>C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T2%\%T1%*.pdf><BREAK><ENDIF><ENDREP><ENDIF>

Link to comment
Share on other sites

Cyberchief,

 

Thank you. I haven't tried it yet, but I will when I come home from work.

 

However, the question remains, will your code loop through the folder and if it finds any match on ANY part of the file name(from the folder name) with ALL/ANY of the files, will it move it to the folder with a match in the folder name?

 

This is what I was ultimately getting at.

 

Joe and Strathos I want to thank you. Please feel free to join in. I want to learn. I am frustrated at my lack of computer knowledge and programming, but as the saying goes "One day at a time". Someday the light bulb will turn on.

 

Thanks!

 

Pat

Link to comment
Share on other sites

will your code loop through the folder and if it finds any match on ANY part of the file name(from the folder name) with ALL/ANY of the files, will it move it to the folder with a match in the folder name?

If the folder has multiple words in the name... it will not match "any" of those words of the folder to the name of the file. This will match the entire Folder name to ANY word in the file. So, in your example, your folder had a title of "Excel". If your file is "Excel Tips" or "Excel Functions" or "Excel blah blah"... it will move it. Again, that is if the folder itself is 1 word... If the folder is 2 words, say "Excel Documents"... then the file must contain the words "Excel Documents" somewhere in the name.

Link to comment
Share on other sites

Try this... This will process each folder, and break out every word in the folder name and try and match it to any word in the file name. Caution... if you have common words like "And" or "Or" or "The"... it will process these as if they said "Excel". So you want to be careful with the naming convention of your folders.

 

 

If File Ready "%T1%*.pdf"
 Repeat with Folder
   Variable Modify String: Copy %T2% to %T3%
   Replace " " with ";" in %T3%
   Variable Modify String: Append ";" to %T3%
   Repeat Until %T3% Does not contain ";"
     Variable Set Integer %N1% from Position of Text in Variable %T3%
     Variable Modify String: Copy Part of %T3% to %T4%
     Variable Modify String: Delete Part of %T3%
     Replace ";" with "" in %T4%
     If Variable %T1% contains variable %T4%
       Move File or Files: "%T1%*.pdf"
       Break
     End If
   Repeat End
 Repeat End
End If

 

<IFOTH:19:2:C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T1%*.pdf><REP3:07:000006:000001:0002:0:01:C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing><TMVAR2:09:03:02:000:000:><TMVAR2:21:03:01:000:000: ;><TMVAR2:07:03:00:000:000:;><REP3:08:000008:000001:0003:0:01:;><IVAR2:01:13:3:;><TMVAR2:10:04:03:001:N01:><TMVAR2:11:03:00:001:N01:><TMVAR2:21:04:01:000:000:;><IFVAR2:4:01:7:T4><DOFILE:07:NN:C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T1%*.pdf>C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T2%\%T1%*.pdf><BREAK><ENDIF><ENDREP><ENDREP><ENDIF>

Link to comment
Share on other sites

Hello again

 

Forget about the sample I posted before, its too messy.

 

 

If the Folder that Contains the Subfolders is NOT inside the folder that contains the Files, this macro should work. Just run it, no need to change anything.

 

<CLEARVAR1:T:20:21><REM2:Get Main Folder 1 and 2 Path from Registry><REGRSTR:20:HKEY_CURRENT_USER\Folder F><REGRSTR:21:HKEY_CURRENT_USER\Folder S><REM2:Select Main Folder and save it to Registry (First Time Run)><IFVAR2:1:20:1:><TVAR2:20:10:~ Please Select the Folder that contains the Files ~><REGWSTR:20:HKEY_CURRENT_USER\Folder F><ENDIF><IFVAR2:1:21:1:><TVAR2:21:10:~ Please Select the Folder that contains the Subfolders ~><REGWSTR:21:HKEY_CURRENT_USER\Folder S><ENDIF><DIS:<TBOX4:T:1:000373000269000409000157:000:Folder F S%T20%
-
%T21%><REM2:Get Full File Path (T10)><REP3:07:000002:000001:0010:0:01:%T20%><REM2:Get File Name (T1)><REP3:07:000001:000001:0001:0:01:%T20%><DIS:<TBOX4:T:1:000373000269000409000157:000:-%T10%
-
%T1%><IFVAR2:4:10:7:T1T><BREAK><ENDIF><ENDREP><REM2:Get First Word (Folder Name) from T1 to T2><IVAR2:01:13:1: ><TMVAR2:10:02:01:001:N01:><TMVAR2:13:02:00:000:000:><TMVAR2:01:02:00:000:000:><DIS:<TBOX4:T:1:000373000269000418000173:000:Done%T10%
-
%T1%
-
%T2%><REM2:Move File><IFOTH:02:1:%T21%\%T2%><AND><IFOTH:09:2:%T21%\%T2%\%T1%><DOFILE:07:NN:%T10%>%T21%\%T2%\%T1%><ENDIF><ENDREP>

 

What will this macro do:

 

It will take the First word of every file that are inside the "Files Folder" and move them to the Folder that contains the Subfolders (Excel, Word, PDF, Access, whatever) that matches the said word.

 

It will move only those files whose first filename word matches with an existing folder.

 

It will NOT watch for files that already are inside the Folder that Contains the Subfolders.

 

 

Uhm.. lets say:

 

· You have a Folder that contains the files: "Word data.doc" and "PDF guide.pdf"

· You have another folder that contains the subfolders: "Word" and "PDF"

 

ME will take the two Files and move them, based on the first word of each one, to the Folders.

 

 

It was fun to make it.

 

If it works for you, you can learn some looking at the Script.

 

Good luck!

 

PS: IF you want to be asked Again for those 2 folders, use this macro:

<REGDELVAL:HKEY_CURRENT_USER\Folder F><REGDELVAL:HKEY_CURRENT_USER\Folder S>

 

PS2: hope you can understand me better than I do :rolleyes:.

Link to comment
Share on other sites

Cyberchief,

 

Here is what I have, BUT I guessed how to do this. I created this for quite some time(by chance it worked). I use a prompt to get the first name of file and it works to get more than one word of the file:

 

I want to know how it could automatically recognize the first(maybe the second word of the folder and bring the matching files together).

 

I used a prompt on this:

 

Change Directory/Folder: "C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing"

Variable Set String %T1% from Prompt

Create Folder: "%T1%"

If Folder Exists "C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T1%"

Open Folder: %T1%

End If

If File Exists "%T1%*.pdf"

Move File or Files: "%T1%*.pdf"

End If

If File Exists "%T1%*.pdf"

Move File or Files: "%T1%*.pdf"

End If

If File Exists "%T1%*.pdf"

Move File or Files: "%T1%*.pdf"

End If

End If

 

<DOFILE:01:NN:C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing>><TVAR2:01:02:FFolder NameFFCenter:Center><DOFILE:02:NN:%T1%>><IFOTH:02:1:C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T1%><MYCOMP:%T1%><ENDIF><IFOTH:01:2:C:\My Cabinets\Pat Gennarelli\Inbox\%T1%*.pdf><DOFILE:07:NN:C:\My Cabinets\Pat Gennarelli\Inbox\%T1%*.pdf>C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T1%\%T1%*.pdf><ENDIF><IFOTH:01:2:C:\Documents and Settings\Gabriella Gennarelli\Desktop\%T1%*.pdf><DOFILE:07:NN:C:\Documents and Settings\Gabriella Gennarelli\Desktop\%T1%*.pdf>C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T1%\%T1%*.pdf><ENDIF><IFOTH:01:2:C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T1%*.pdf><DOFILE:07:NN:C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T1%*.pdf>C:\My Cabinets\Mortgage Files\Loans IN Processing\4. Loans In Processing\%T1%\%T1%*.pdf><ENDIF><ENDIF>

 

How can I get this to work by itself without the prompt?

 

Pat

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