forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Compact Path function

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced VDS 5 Source Code
View previous topic :: View next topic  
Author Message
DaveŽ
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 403
Location: Australia

PostPosted: Wed Apr 25, 2007 7:43 am    Post subject: Compact Path function Reply with quote

Just thought I'd share my user defined function for truncating long paths and filenames. It returns truncated paths/filenames similiar to the Windows PathCompactPathExA Function.

For example, if the long path is "C:\Program Files\Visual Dialog Script\Demos" and the 1st parameter is 40, PathCompactPathEx will return "C:\...\Visual Dialog Script\Demos". Or if the 1st parameter is 30, PathCompactPathEx will return "C:\...\Demos"

Note:
If the 2nd parameter is a file name that is too long, rather than a path, the file name will be truncated to the max characters length (the 1st parameter), including the ellipsis. For example, if the input file name is "My Filename.txt" and the 1st parameter is 10, PathCompactPathEx will return "My Fil...".

I've included an optional 3rd parameter to retain the file's extension in the returned truncated filename, if desired. For example, if the 3rd parameter is 1, and the input file name is "My Filename.txt" and the 1st parameter is 12, PathCompactPathEx will return "My F...txt".


Still to do:
Include compacting of web addresses - preferably without using any 3rd-party librarys.


Code:
  #define function,PathCompactPathExA

  # Use:
  # %x = @PathCompactPathExA(<length>,<path-to-compact>,<show-ext>)
  # Show ext is optional - use 1 for yes


:PathCompactPathExA
  if @both(@numeric(%1),%2)
    %%maxLen = %1
    %%Path = %2
    %%PathLen = @len(%%Path)
    if @greater(%%PathLen,%%maxLen)
      if @not(@path(%2))
        if @equal(1,%3)
          %%Ext = @ext(%%Path)
          %%newPath = @substr(%%Path,1,@diff(%%maxLen,@sum(3,@len(%%Ext))))...%%Ext
        else
          %%newPath = @substr(%%Path,1,@diff(%%maxLen,3))...
        end
      else
        %%Root = @substr(%%Path,1):\...\
        %%wLen = @diff(%%maxLen,7)
        %%mPath = @substr(%%Path,@diff(%%PathLen,%%wLen),%%PathLen)
        %%mPath = @strdel(%%mPath,1,@pos(\,%%mPath))
        %%newPath = %%Root%%mPath
      end
    else
      %%newPath = %%Path
    end
  else
    exit 0
  end
  exit %%newPath


Thanks to Aslan's help here:
http://www.vdsworld.com/forum/viewtopic.php?p=31454#31454

_________________
cheers

DaveŽ
Back to top
View user's profile Send private message Visit poster's website
Tdk161
Valued Contributor
Valued Contributor


Joined: 08 Feb 2005
Posts: 395
Location: ITALY

PostPosted: Sun Jun 12, 2011 5:49 pm    Post subject: Reply with quote

Hi DaveŽ,

Very Happy thank you a lot, it's what I needed
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced VDS 5 Source Code All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum




Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group