| View previous topic :: View next topic |
| Author |
Message |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sat Oct 04, 2003 9:38 am Post subject: Shortname to LFN? |
|
|
Does anyone know of a quick way to convert a shortname to long name?
The "SearchtreeforFile" example by CodeScript does this in a round
about way, but it takes a bit too much time to do it's job. I tried working
out some other api's, but just am not good at working with the api's yet,
so I'm hoping that maybe someone else has a way already that's quick
and effective at converting the shortname of a directory or file to long
name.
Thanks in advance,
-Garrett _________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
| Back to top |
|
 |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Sat Oct 04, 2003 2:14 pm Post subject: |
|
|
Hi Garrett
Try This :
I just omitted this from Dirpathinfo example somehow.
I will add it to that later anyway.
| Code: | #-----------------------------------------------------------------------------#
# #
# Default script template - to change it edit <vdspath>\default.dsc #
# #
# Author: CodeScript #
# #
# Copyright: #
# #
#-----------------------------------------------------------------------------#
#DEFINE FUNCTION,Longname
REM Make sure such a file exists
%A = @SHORTNAME(C:\testfolder with a long file name\New Text Document.txt)
INFO %A!
INFO @LONGNAME(%A)!
EXIT
:Longname
LOADLIB kernel32
IF %1
%P = %1
%D = @FILL(256)
%A = @LIB(kernel32,GetLongPathNameA,int:,@ADDR("%P"),@ADDR("%D"),int:256)
%D = @ADJUST(%D)
END
FREELIB kernel32
EXIT %D |
________________________________________________________________________________________ _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sat Oct 04, 2003 5:29 pm Post subject: |
|
|
Ohhhhhhhh Oh!@ Thank you CodeScript!!!
That does the job so much quicker than what I was doing!
Thank you! Thank you! Thank you! Thank you! Thank you!
-Garrett _________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Sat Oct 04, 2003 5:34 pm Post subject: |
|
|
Nice work CodeScript.  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Sat Oct 04, 2003 5:46 pm Post subject: |
|
|
Thanks for the comments  _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sat Oct 04, 2003 7:36 pm Post subject: |
|
|
You don't know how much of a time saver that was for me. I was using
your searchforfirstfile api. I was having to write a blank file to a directory
and then using that api to find it just so I could get the LFN for the
directory, and you know that api can take some time to search for the file,
especially if you have to loop through it several times doing this for
several directories.
I owe you one for posting this LFN api for me.
-Garrett _________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
| Back to top |
|
 |
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Sat Oct 04, 2003 8:36 pm Post subject: |
|
|
Another approach would be this one:
| Code: | | info @file(c:\progra~1,D) |
|
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sat Oct 04, 2003 10:01 pm Post subject: |
|
|
CodeScript.... Is there anyreason this api would not work on XP? I can't
get it to work on XP.. Works like a charm on 9x though.
Tommy,
Try this:
| Code: | | info @file(C:\PROGRA~1\COMMON~1,D) |
and see if it gives you a full lfn from that.
-Garrett _________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
| Back to top |
|
 |
PGWARE Web Host

Joined: 29 Dec 2001 Posts: 1565
|
Posted: Sat Oct 04, 2003 10:36 pm Post subject: |
|
|
| Just tried CodeScripts code on Windows XP Home on a box that was just reformated 2 hours ago and it works perfectly. Returns the full path. |
|
| Back to top |
|
 |
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Sun Oct 05, 2003 12:39 am Post subject: |
|
|
I think an approach like this one would work too:
| Code: | %%path = C:\PROGRA~1\COMMON~1
gosub shorttolongdir
info %%result
exit
:shorttolong
if @equal(@substr(%%path,@len(%%path)),\)
%%path = @strdel(%%path,@len(%%path))
end
%p = @pos("\",%%path)
%%result = @substr(%%path,1,@pred(%p))
%%dir = @substr(%%path,@succ(%p),@len(%%path))
while @greater(@pos("\",%%dir),0)
%p = @pos("\",%%dir)
%%result = %%result"\"@substr(%%dir,1,@pred(%p))
%%result = @file(%%result,D)
%%dir = @strdel(%%dir,1,%p)
wend
%%result = %%result"\"%%dir
exit
:shorttolongdir
gosub shorttolong
%%result = @file(%%result,D)
exit
:shorttolongfile
gosub shorttolong
%%result = @file(%%result)
exit |
|
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sun Oct 05, 2003 1:47 am Post subject: |
|
|
Apologies to CodeScript and Tommy.....
Both your codes work. It was my fault that they didn't work on XP. I
overlooked a difference in output from the command line and when I used
substr() to get the shortname of the directory, on XP, I was getting other
data before the directory path, which of course cause both codes to not
give a proper return.
Thank you both for your help and code.
-Garrett _________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
| Back to top |
|
 |
vdsalchemist Admin Team

Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Sun Oct 05, 2003 4:30 am Post subject: |
|
|
Hi Garrett,
I gave you this ability with Gadget a long time ago. Also note that I did not use the API that CodeScript mentioned because there are some limitations to it. This is what MicroSoft had to say about the GetLongPathName API function....
| Quote: | | Windows NT and Windows 95: Include an additional header file called NewAPIs.h to make GetLongPathName available on these operating systems. The function is not implemented natively, but by a wrapper that utilizes other native functions on these systems. See the header file for details of the use of preprocessor directives that make the function available. If you do not have this header file, it can be obtained by downloading the most recent SDK from the SDK Update Site. |
The function that I built with Gadget uses a similar method to this but does not use the GetLongPathName function. Also note that if the path is longer than 256 characters GetLongPathName will not work on Win9x and ME. This is another reason that I built a function myself... Anyway I just thought you should know this before you rolled out anything using GetLongPathName. _________________ Home of
Give VDS a new purpose!
 |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sun Oct 05, 2003 5:04 am Post subject: |
|
|
Johnny, thanks for the info... Sorry about forgetting the long file name
ability in Gadget.
-Garrett _________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
| Back to top |
|
 |
vdsalchemist Admin Team

Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Sun Oct 05, 2003 3:15 pm Post subject: |
|
|
Garrett,
It's no big deal. Just a reminder. _________________ Home of
Give VDS a new purpose!
 |
|
| Back to top |
|
 |
|