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 


Shortening long paths

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Fri Jan 12, 2007 2:17 pm    Post subject: Shortening long paths Reply with quote

Is there an inbuilt function, a DSU, DLL or an API command that can shorten long path names?

e.g

C:\Documents and Settings\Some User Name\Favourites

to

C:\...\Some User Name\Favourites

or

C:\...\Favourites

_________________
cheers

Dave
Back to top
View user's profile Send private message
Rubes_sw
Valued Contributor
Valued Contributor


Joined: 11 Jun 2001
Posts: 625
Location: Northern Ireland

PostPosted: Fri Jan 12, 2007 2:20 pm    Post subject: Reply with quote

Hi dave

does @shortname() not do it.

Nathan
Back to top
View user's profile Send private message Send e-mail Visit poster's website
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Fri Jan 12, 2007 2:24 pm    Post subject: Reply with quote

PS I did write a user defined function a while ago:
Code:
:PathLen
  rem %X = @len(%1)
  if @greater(@len(%1),%2)
    option fieldsep,"\"
    parse "%A;%B;%C",%1
    if %C
      %X = %A\...\@substr(%1,@sum(@len(%B),5),@len(%1))
      # Convert 2nd directory name to ... if needed
      if @greater(@len(%X),%2)
        parse "%A;%B;%C;%D",%X
        if %D
          %X = %A\...\@substr(%X,@sum(@len(%C),9),@len(%X))
          # Convert 3rd directory name to ... if needed
          if @greater(@len(%X),%2)
            parse "%A;%B;%C;%D;%E",%X
            if %E
              %X = %A\...\@substr(%X,@sum(@len(%D),13),@len(%X))
            end
          end
        end
      end
    end
    option fieldsep,"|"
  else
    %X = %1
  end
  exit %X

but if I rememer correctly it currently shortens the above path example to:

C:\...\...\Favourites

and only handles shortening the first 3 directories. Using my function I'm going to have to keep track of each full path that relates to each shortened 'display' path. But I though maybe there's a better way?

_________________
cheers

Dave
Back to top
View user's profile Send private message
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Fri Jan 12, 2007 2:28 pm    Post subject: Reply with quote

Rubes_sw wrote:
does @shortname() not do it.


Hi Nathan,

@shortname() returns the DOS shortnames (if they exist, otherwise it gives an error). i.e. The above example would become something like: C:\DOCUME~1\SOME~1\FAVOUR~1 which is not really what I'm after.

_________________
cheers

Dave
Back to top
View user's profile Send private message
uvedese
Contributor
Contributor


Joined: 21 Jan 2006
Posts: 169
Location: Spain

PostPosted: Fri Jan 12, 2007 3:31 pm    Post subject: Reply with quote

Hi all Very Happy

It's very easy to do, using my Unit "argDSU".

You can download from this url:

http://vds.uvedese.es/index.php?option=com_content&task=view&id=130&Itemid=52

ArgDSU works with arguments separated by a " separating character ". For more information you can consult the documentation of argDSU (in Spanish, but it's very easy).

try this scritp:

Code:


 #include argDSU.dsu
 
 %%path = c:\Documents and Settings\user\My Documents
 
 # "arg(count)" count the number of arguments
 # into "%%path" separated for "\"
 
 %%number_arguments = @arg(count,%%path,\)
 
 if @greater(%%number_arguments,2)
 
   # "arg(item)" returns the indicate item (argument)
   # inside "%%path" separated for "\"
   
   info @arg(item,%%path,1,\)"\...\"@arg(item,%%path,%%number_arguments,\)
 else
 
   info %%path
 end


Cool
____________

visit uVeDeSe site: http://www.uvedese.es


Last edited by uvedese on Wed Apr 02, 2008 8:39 pm; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Fri Jan 12, 2007 5:26 pm    Post subject: Reply with quote

If you can figure it out, PathCompactPathExA will do what you want.
It wants a pointer to a string as the first param, and getting a pointer to a VDS variable is rediculous.
Here's the info at MSDN though:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/shlwapi/path/pathcompactpathex.asp

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
vtol
Valued Contributor
Valued Contributor


Joined: 05 Feb 2004
Posts: 656
Location: Eastern Indiana

PostPosted: Sat Jan 13, 2007 2:59 am    Post subject: Reply with quote

On the fly I thought of this way which you could convert to a simple loop to cover very long paths, plus you have more of a editible full VDS controlible option this way maybe.

This would also cover for a DOS CD\ function (back one folder) I think Idea As you can see it could be unlimited past the example below by just adding more to it or adjusting a customized loop.

Code:
%%counter = 0
%%path = c:\Documents and Settings\user\four deep\five deep\My Documents

#  EXAMPLE1:   %%path = c:\My Documents
#  EXAMPLE2:   %%path = c:\Documents and Settings\My Documents
#  EXAMPLE3:   %%path = c:\Documents and Settings\user\My Documents
#  EXAMPLE4:   %%path = c:\Documents and Settings\user\four deep\My Documents
#  EXAMPLE5:   %%path = c:\Documents and Settings\user\four deep\five deep\My Documents

%%last_folder = @name(c:\Documents and Settings\user\My Documents)

%%path = @path(%%path)
%%counter = @succ(%%counter)
IF @equal(@LEN(%%path),3)
 Goto process
END

info %%path@CR()@CR()emulate DOS CD\ command @fill(4)back %%counter folder"("s")"
%%counter = @succ(%%counter)
%%path = @SUBSTR(%%path,1,-1)
%%path = @path(%%path)
IF @equal(@LEN(%%path),3)
 Goto process
END

info %%path@CR()@CR()emulate DOS CD\ command @fill(4)back %%counter folder"("s")"
%%counter = @succ(%%counter)
%%path = @path(%%path)
%%path = @SUBSTR(%%path,1,-1)
%%path = @path(%%path)
IF @equal(@LEN(%%path),3)
 Goto process
END

info %%path@CR()@CR()emulate DOS CD\ command @fill(4)back %%counter folder"("s")"
%%counter = @succ(%%counter)
%%path = @path(%%path)
%%path = @SUBSTR(%%path,1,-1)
%%path = @path(%%path)
IF @equal(@LEN(%%path),3)
 Goto process
END

info %%path@CR()@CR()emulate DOS CD\ command @fill(4)back %%counter folder"("s")"
%%counter = @succ(%%counter)
%%path = @path(%%path)
%%path = @SUBSTR(%%path,1,-1)
%%path = @path(%%path)
IF @equal(@LEN(%%path),3)
 Goto process
END

info %%path@CR()@CR()emulate DOS CD\ command @fill(4)back %%counter folder"("s")"
%%counter = @succ(%%counter)
%%path = @path(%%path)
%%path = @SUBSTR(%%path,1,-1)
%%path = @path(%%path)
IF @equal(@LEN(%%path),3)
 Goto process
 ELSE
 info need to be deeper"," add some more!
 goto done
END

:process
IF @equal(%%counter,1)
 %%result = C:\%%last_folder@CR()@CR()RESULT of ROOT path
 INFO %%result
 Goto done
END
IF @equal(%%counter,2)
 %%result = C:\...\%%last_folder@CR()@CR()RESULT of @pred(%%counter) deep
 INFO %%result
 Goto done
END
IF @equal(%%counter,3)
 %%result = C:\...\...\%%last_folder@CR()@CR()RESULT of @pred(%%counter) deep
 INFO %%result
 Goto done
END
IF @equal(%%counter,4)
 %%result = C:\...\...\...\%%last_folder@CR()@CR()RESULT of @pred(%%counter) deep
 INFO %%result
 Goto done
END
IF @equal(%%counter,5)
 %%result = C:\...\...\...\...\%%last_folder@CR()@CR()RESULT of @pred(%%counter) deep
 INFO %%result
 Goto done
END
:done
EXIT
Back to top
View user's profile Send private message Visit poster's website
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Sun Jan 14, 2007 9:48 pm    Post subject: Reply with quote

Quote:
If you can figure it out, PathCompactPathExA will do what you want.
It wants a pointer to a string as the first param, and getting a pointer to a VDS variable is rediculous.


What if you put the path string in an edit box or text element and pointed to it?

EDIT: Never mind ...I should have read the info at the link first Wink


Last edited by Aslan on Sun Jan 14, 2007 10:43 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Sun Jan 14, 2007 10:36 pm    Post subject: Reply with quote

Will this do what you want??

Change %%maxLen to suite your needs.

Code:

 %%maxLen = 60
 %%Path = @input(Enter Path to test..)
 %%PathLen = @len(%%Path)
 %%Root = @substr(%%Path,1):\...\
 %%wLen = @diff(%%maxLen,7)
 %%mPath = @substr(%%Path,@diff(%%PathLen,%%wLen),%%PathLen)
 %%mPath = @strdel(%%mPath,1,@pos(\,%%mPath))
 %%newPath = %%Root%%mPath
 info %%newPath
 exit
Back to top
View user's profile Send private message Send e-mail
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Tue Jan 16, 2007 2:09 pm    Post subject: Reply with quote

Excellent, Aslan! Thanks Very Happy

The other people's suggestions were helpful too. ArgDSU will come in handy.

_________________
cheers

Dave
Back to top
View user's profile Send private message
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Thu Nov 15, 2007 8:35 pm    Post subject: Reply with quote

Hi All,
Sorry I have not replied to this until now. Below is the code to use the PathCompactPathEx Win32 API function.

Code:

#-----------------------------------------------------------------------------#
#                                                                             #
# Demo to use the PathCompactPathEx Win32 API function from shlwapi.dll       #
#                                                                             #
# Author:  Johnny Kinsey                                                      #
#                                                                             #
# Copyright: Copyright © 2007 DragonSphere Software                           #
#                                                                             #
#-----------------------------------------------------------------------------#

#Define Function,PathCompactPathEx

%%CompactPath = @PathCompactPathEx(https://msdn2.microsoft.com/en-us/library/ms628549.aspx,45)
If %%CompactPath
  Info %%CompactPath
Else
  Warn Could not shorten path.
End
Exit
:PathCompactPathEx
 %R =
 LoadLib shlwapi.dll
 If @Null(%1)
   error 20
 Else
   If @Null(%2)
     %2 = 256
   End
   %A = @fill(@len(%1),,Z)
   %S = @lib(shlwapi,PathCompactPathExA,BOOL,INT:@addr("%A"),STR:%1,INT:%2,INT:0)
   If %S
    %R = @Trim(%A)
   Else
     error -1
   End
 End
 FreeLib shlwapi
Exit %R

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Fri Nov 16, 2007 8:22 am    Post subject: Reply with quote

Thanks Johnny.

BTW I changed it a bit to avoid unhandled exception "" errors if the number of characters in the input string are less than the specified number of characters plus 2.

Code:
#-----------------------------------------------------------------------------#
#                                                                             #
# Demo to use the PathCompactPathEx Win32 API function from shlwapi.dll       #
#                                                                             #
# Author:  Johnny Kinsey                                                      #
#                                                                             #
# Copyright: Copyright © 2007 DragonSphere Software                           #
#                                                                             #
#-----------------------------------------------------------------------------#

  #define function,PathCompactPathEx

  %%CompactPath = @PathCompactPathEx(https://msdn2.microsoft.com/en-us/library/ms628549.aspx,45)
  if %%CompactPath
    info %%CompactPath
  else
    warn Could not shorten path.
  end
  exit

:PathCompactPathEx
  %R =
  loadlib shlwapi.dll
  if @null(%1)
    error 20
  else
    if @null(%2)
      %2 = 256
    end
    if @greater(%2,@succ(@len(%1)))
      %R = %1
    else
      %A = @fill(@len(%1),,Z)
      %S = @lib(shlwapi,PathCompactPathExA,BOOL,INT:@addr("%A"),STR:%1,INT:%2,INT:0)
      if %S
        %R = @trim(%A)
      else
        error -1
      end
    end
  end
  freelib shlwapi
  exit %R

_________________
cheers

Dave
Back to top
View user's profile Send private message
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Fri Nov 16, 2007 7:06 pm    Post subject: Reply with quote

Dave,
I guess it's ok to put that inside the function. I guess I could fix the default to check the length first but I would think it should be up to the programmer to make sure that the path actually needs to be truncated before they call the function.

You usually use this function to truncate the path for a Editbox or listbox or some other element so it fits and does not cause scrollbars to show or be longer than the box and without a scroll bar it leave the user wandering how to get to the end of the path.

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Fri Nov 16, 2007 11:17 pm    Post subject: Reply with quote

dragonsphere wrote:
but I would think it should be up to the programmer to make sure that the path actually needs to be truncated before they call the function.

Agreed

Though with unhandled exception errors it can be very difficult to determine what is causing the error. The first few errors I got while testing it showed the VDS script's line number. But after that it was showing DLL line numbers (like 17500).

I guess it would be better to return a VDS error message than just return the full path unchanged (see below). This way the programmer would know that they need to check to the path length before calling the function.

I also don't like having possible exit points in a function (like 'error -1') if the library has not been unloaded. Is there any reason why I should not have loadlib, @fill(), @lib() and freelib all together like the following Question

Code:
:PathCompactPathEx
  %R =
  if @null(%1)
    error 20
  else
    if @null(%2)
      %2 = 256
    elsif @greater(%2,@succ(@len(%1)))
      error 13
    end
    loadlib shlwapi.dll
    %A = @fill(@len(%1),,Z)
    %S = @lib(shlwapi,PathCompactPathExA,BOOL,INT:@addr("%A"),STR:%1,INT:%2,INT:0)
    freelib shlwapi
    if %S
      %R = @trim(%A)
    else
      error -1
    end
  end
  exit %R


BTW what does 'error -1' do Question
I tested it and it seems to do nothing. But I do remember reading about error -1 here before (but can't find it in the help file).


The PathCompactPathEx Function sometimes returns some strange things if the path ends in a file extension, like C:\notepad.exe becomes '...notepad...'. Note the 3rd and 4th results below. Also note that the the 2nd and 5th results are as expected.

Code:
https://msdn2.microsoft.com/en-us/library/ms628549.aspx - 45     
https://msdn2.microsoft.com.../ms628549.aspx     

https://msdn2.microsoft.com/index.htm - 25     
https://msd.../index.htm     

https://msdn2.microsoft.com - 15     
.../msdn2.m...     

C:\Windows\System32\notepad.exe - 15     
...\notepad...     

C:\Windows\System32\dotcom.com - 15     
...\dotcom.com     

C:\Windows\System32\notepad - 25     
C:\Windows\Sy...\notepad     

My Filename - 10     
My Fil...     

My Filename.exe - 10     
My Fil...     

_________________
cheers

Dave
Back to top
View user's profile Send private message
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Mon Nov 19, 2007 4:50 pm    Post subject: Reply with quote

Dave® wrote:
Though with unhandled exception errors it can be very difficult to determine what is causing the error. The first few errors I got while testing it showed the VDS script's line number. But after that it was showing DLL line numbers (like 17500).


Agreed

Dave® wrote:
I guess it would be better to return a VDS error message than just return the full path unchanged (see below). This way the programmer would know that they need to check to the path length before calling the function.


Again I agree with you on this point too. It is always better to handle errors than to just ignore them and hope they go away.

Dave® wrote:
I also don't like having possible exit points in a function (like 'error -1') if the library has not been unloaded. Is there any reason why I should not have loadlib, @fill(), @lib() and freelib all together like the following Question


There is no reason why you cannot do this. The API functions that load and release DLL's are smart enough to handle the scenario where you do a loadlib twice without a freelib. When the process shuts down it's heap will be cleared anyway. It is however good practice to make sure that you freelib before exiting since this can cause GDI and User leaks with some DLL's.

Dave® wrote:
BTW what does 'error -1' do Question
I tested it and it seems to do nothing. But I do remember reading about error -1 here before (but can't find it in the help file).


error -1 sets @OK() to false.


Dave® wrote:
The PathCompactPathEx Function sometimes returns some strange things if the path ends in a file extension, like C:\notepad.exe becomes '...notepad...'. Note the 3rd and 4th results below. Also note that the the 2nd and 5th results are as expected.

Code:
https://msdn2.microsoft.com/en-us/library/ms628549.aspx - 45     
https://msdn2.microsoft.com.../ms628549.aspx     

https://msdn2.microsoft.com/index.htm - 25     
https://msd.../index.htm     

https://msdn2.microsoft.com - 15     
.../msdn2.m...     

C:\Windows\System32\notepad.exe - 15     
...\notepad...     

C:\Windows\System32\dotcom.com - 15     
...\dotcom.com     

C:\Windows\System32\notepad - 25     
C:\Windows\Sy...\notepad     

My Filename - 10     
My Fil...     

My Filename.exe - 10     
My Fil...     


Please read the https://msdn2.microsoft.com/en-us/library/ms628549.aspx MSDN article for more details about this function. The information you are suggesting here fits the description of this function. Also note I did not write the API function so if it is showing something unexpected I guess you could get on any number of Microsoft forums and post your findings there. They may fix it to your specifications or at least explain in more detail how and why it chooses to truncate the paths the way it does Question I only posted this as an alternative to using the VDS string functions since this function prob. truncates paths in a way that is more familiar to the common user of Windows programs.

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help 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