Blue Eye Logo

Blue Eye Macro

Automation is freedom
It is currently Sun Nov 18, 2018 8:50 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Resolve path
Thanked: 0 time(s)  Unread post Posted: Fri Oct 26, 2012 9:01 am 
Lifetime VIP Contributor
Lifetime VIP Contributor
User avatar



Joined: Tue Nov 23, 2010 10:51 am
Posts: 212
Location: Pandora
Been thanked: 97 time(s)
Has thanked: 66 time(s)
Contribution Points: 8643
this is
Code:
Plugins.Resolve path("", "")
it's used like
Code:
File.Resolve path("", "")
but the plugin version can resolve more paths, such as
Code:
%userprofile%\Documents\c?.t*
which matches "C:\Users\User\Documents\cc.txt". please report issues.

get it in the plugin suite, see link in sig

Image


Last edited by sickslug on Sat Nov 17, 2012 4:55 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Resolve path
Thanked: 1 time(s)  Unread post Posted: Fri Oct 26, 2012 12:33 pm 
Partner / Developer
Partner / Developer
User avatar



Joined: Mon Jan 18, 2010 11:51 am
Posts: 4523
Been thanked: 1192 time(s)
Has thanked: 132 time(s)
Contribution Points: 32845
Nice, thanks for sharing.

Perhaps you implementation should be moved into the actual code base for the next release?
To add your functionality to the build in "File.Resolve path" function.

_________________
Blue Eye - Developer / Moderator
Code:
Gigus


Please read the rules about contribution points - click here

Do you know everything about BE, the forum, licenses and contribution points?
Please take a minute to read this introduction & guidelines.


Top
 Profile  
Reply with quote  
 Post subject: Re: Resolve path
Thanked: 1 time(s)  Unread post Posted: Fri Oct 26, 2012 9:44 pm 
Lifetime VIP Contributor
Lifetime VIP Contributor
User avatar



Joined: Tue Nov 23, 2010 10:51 am
Posts: 212
Location: Pandora
Been thanked: 97 time(s)
Has thanked: 66 time(s)
Contribution Points: 8643
that's fine with me, but if you could find a way to work
Code:
System.Environment.GetEnvironmentVariable(String)
into your code it might be easier than importing everything

here's all the code in c# if you want it - it seems ok but i haven't tested every possibility
Code:
    [Serializable]
    public class paths : BaseInstruction
    {
        public override void InitArguments()
        {
            // 0
            AddArguments(new PluginArgument(PluginArgument.ArgumentType.Text,
                100, "Path to resolve", "Path to resolve. wildcards allowed in trailing folder or file name only"
                + System.Environment.NewLine + "\tex: \"%MyDocuments%\\picture???.*\" matches \"C:\\Users\\Entropy\\Documents\\picture001.png\""
                + System.Environment.NewLine + "wildcard \"?\" matches exactly one character"
                + System.Environment.NewLine + "wildcard \"*\" matches any number of characters"
                + System.Environment.NewLine + "first matching path will be returned, files have priority to folders"
                + System.Environment.NewLine + "Other valid directories for use inside %\'s include:"
                + System.Environment.NewLine + "Description, ApplicationData, CommonApplicationData, LocalApplicationData, Cookies, Desktop"
                + System.Environment.NewLine + "Favorites, History, InternetCache, Programs, MyComputer, MyMusic, MyPictures, MyVideos, Recent"
                + System.Environment.NewLine + "SendTo, StartMenu, Startup, System, Templates, DesktopDirectory, Personal, MyDocuments, ProgramFiles"
                + System.Environment.NewLine + "CommonProgramFiles, AdminTools, CDBurning, CommonAdminTools, CommonDocuments, CommonMusic, CommonOemLinks"
                + System.Environment.NewLine + "CommonPictures, CommonStartMenu, CommonPrograms, CommonStartup, CommonDesktopDirectory, CommonTemplates"
                + System.Environment.NewLine + "CommonVideos, Fonts, NetworkShortcuts, PrinterShortcuts, UserProfile, CommonProgramFilesX86, ProgramFilesX86"
                + System.Environment.NewLine + "Resources, LocalizedResources, SystemX86, Windows"));
            // 1
            AddArguments(new PluginArgument(PluginArgument.ArgumentType.Text,
                100, "Save to variable", "Save to variable. no curlybraces."
                + System.Environment.NewLine + "\tex: \"myvar\""
                + System.Environment.NewLine + "variable will be blank if no matches are found."));
        }

        public override void Execute()
        {
            string inPath = Arguments[0].Value.ToString();

            // in case the path has no "\", pattern starts as wildcard
            string pattern = "*";
           
            // since we want to keep the original and have a working variable...
            string path = inPath;

            // since we use the directory seperator a lot...
            string ds = Path.DirectorySeparatorChar.ToString();
            if (path.Contains(ds))
            {
                pattern = path.Substring(path.LastIndexOf(ds) + 1);
                path = path.Remove(path.LastIndexOf(ds + pattern));
            }

            // in case the path starts with a special folder...
            if (path.StartsWith("%"))
            {
                int len = inPath.LastIndexOf("%");
                string ev = inPath.Substring(1, len - 1);
                path = Environment.GetEnvironmentVariable(ev) + path.Substring(len + 1);
            }

            // look for folders that match the search, ignore errors
            string[] dirList = new string[] { };
            try
            {
                // in case the parent is a drive...
                if (path.EndsWith(":"))
                    dirList = Directory.GetDirectories(path + ds, pattern);
                else
                    dirList = Directory.GetDirectories(path, pattern);
            }
            catch { }

            // look for files that match the search, ignore errors
            string[] filList = new string[] { };
            try
            {
                filList = Directory.GetFiles(path, pattern);
            }
            catch { }

            // combine the path in case searches fail
            path = path + ds + pattern;
           
            // set the variable to the first file found, or else the combined path if it's a file,
            // or else the first found directory, or finally if the combined path is folder
            if (filList.Length > 0)
                SetVariable(Arguments[1].Value.ToString(), Path.GetFullPath(filList[0]));
            else if (File.Exists(path))
                SetVariable(Arguments[1].Value.ToString(), Path.GetFullPath(path));
            else if (dirList.Length > 0)
                SetVariable(Arguments[1].Value.ToString(), Path.GetFullPath(dirList[0]));
            else if (Directory.Exists(path))
                SetVariable(Arguments[1].Value.ToString(), Path.GetFullPath(path));
        }

        public override string Name
        {
            get { return "Resolve path"; }
        }
    }


Top
 Profile  
Reply with quote  
 Post subject: Re: Resolve path
Thanked: 0 time(s)  Unread post Posted: Sat Jan 12, 2013 9:45 am 


Thank you for sharing.


Top
  
Reply with quote  
 Post subject: Re: Resolve path
Thanked: 0 time(s)  Unread post Posted: Sat Feb 16, 2013 6:25 pm 
Partner / Developer
Partner / Developer
User avatar



Joined: Mon Jan 18, 2010 11:51 am
Posts: 4523
Been thanked: 1192 time(s)
Has thanked: 132 time(s)
Contribution Points: 32845
Thanks, Ill get it in there!

_________________
Blue Eye - Developer / Moderator
Code:
Gigus


Please read the rules about contribution points - click here

Do you know everything about BE, the forum, licenses and contribution points?
Please take a minute to read this introduction & guidelines.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


You cannot post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group