Jump to content
Macro Express Forums

Define path from path/filename?


Recommended Posts

Before I start what looks as if it might be some routine but tedious coding, have I missed some command(s) that will do this trivial job in a simple way please?

 

I've set the text variable CurrentFile as C:\xyz\whatever\photo.jpg. In practice, I won't know how long the path is. I now want to open the folder with the file selected, ready for me to do

what I want with it manually. Is there for instance a command that will extract just the path from the full filename?

 

Edit: Meanwhile, on the assumption that the answer's No, I've gone ahead and scripted it. One point that has me stumped at present is how to select a file. IOW,. given its full filename, highlight and view it automatically in a large folder? I thought I'd found a way, by using the File/Rename command and using identical names. I thought that might end up with the file selected, but it didn't work.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Here's what I do when I can't be certain a path isn't going to change, or if a specific source file may be renamed by a 3rd party.....

I've set the text variable CurrentFile as C:\xyz\whatever\photo.jpg. In practice, I won't know how long the path is. I now want to open the folder with the file selected, ready for me to do

what I want with it manually. Is there for instance a command that will extract just the path from the full filename?

Maybe this won't suit your needs, Terry, but when I read the post, it sounded to me like you'd benefit from the Set String: Prompt for a filename command.

 

It leaves setting the path in the hands of the user, so it's not going to be fool-proof, but you could probably add some code that compares the selected file against the name of the file that should be selected, and if the actual filename doesn't match, then the user didn't do what they were supposed to do. Ergo, you give a Text Box scolding the user, and telling them to try again; then "Macro Run: this macro" and Macro Stop [don't wait for this macro to finish] (or whatever), and they get to try again.

Link to comment
Share on other sites

Variable Set From File > Get File Path Info

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

I avoid using the Windows Explorer GUI for any type of file manipulations but the one idea I had was that I would first open the Explorer window, highlight the file list then type out the file name only and it should highlight your file.

Link to comment
Share on other sites

Variable Set From File > Get File Path Info

 

Thanks Cory, never used that before, should be very handy. A minor inconvenience seems to be that Path excludes Drive, but that's easy enough to fix. Certainly bound to generate neater script than my method of searching for '/' characters etc.

 

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

I avoid using the Windows Explorer GUI for any type of file manipulations but the one idea I had was that I would first open the Explorer window, highlight the file list then type out the file name only and it should highlight your file.

 

I had exactly the same idea and it worked fine. :rolleyes:

 

After the Open Folder the first entry was already selected so all I had to do was use a TextType. Some timing adjustments were needed, and I also added a Keystroke Speed.

 

BTW, I had no hopes of this working as I'd assumed only the first 3 or 4 keystrokes were used by Windows Explorer. But that was wrongly based on my experience of using the method manually. (If I could hit the keys at say 50 ms intervals I now assume I could emulate the macro by hand!)

 

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

A minor inconvenience with the path.

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

I agree it sucks we can’t have that command output to a glued together variable but we’re looking a gift horse in the mouth. Mainly I am annoyed by the extra variables. Often I want to increment a file name, add something like “ - Output”, or other such thing and I end up extracting all the %File Name Original% to %File Drive%, %File Path%, %File Name%, and %File Ext% and then create yet another variable %File Name New%=”%File Drive%%File Path%%File Name% - Output%File Ext%”. I could use all 4 each time I needed it but it’s more prone to mistakes.

 

I have a file path including name I sue for URLs and other similar tasks. I would repeat until %char%=”” and test to see if it was a slash (in the case of a URL). If it was a slash I would record the repeat iteration to something like %Last Slash%. When it’s all done the integer value is the last slash position and I would copy from 1 to %Last Slash%. Alternatively one can get the length of the string and count backwards until it finds the first slash. No matter how you slice it though the Get File Info is fewer lines of code.

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