long-to-short dir/filenames 
Author Message
 long-to-short dir/filenames


filenames for input

the problem is that I have this filelist.txt  with LONG dir/filenames,
like:

c:\mydirectorya\subdirectorya\longfilename.txt
c:\mydirectoryb\subdirectoryb\longfilenameb.txt
c:\foobar\onetwothree.txt


c:\MYDIRE~1\SUBDIR~1\LONGFI~1.TXT
c:\MYDIRE~2\SUBDIR~2\LONGFI~1.TXT
c:\FOOBAR\ONETWO~1.TXT

I think the only correct way to do this  is to execute and analyze a system
DIR  for each row..
using  AWK, SED, or PERL
anyone knows how to do it?

I'm on Windows 2000,
w2k has   DIR /X for displaying SFN
w98 display SFN with a normal DIR
but both seems to not display the dir shortnames (perhaps you can see them
by executing a DIR for each dir/subdir in the row.. but I think it's a bad
method)

any idea?



Sat, 08 Feb 2003 03:00:00 GMT  
 long-to-short dir/filenames

Quote:


>filenames for input

>the problem is that I have this filelist.txt  with LONG dir/filenames,
>like:

>c:\mydirectorya\subdirectorya\longfilename.txt
>c:\mydirectoryb\subdirectoryb\longfilenameb.txt
>c:\foobar\onetwothree.txt


>c:\MYDIRE~1\SUBDIR~1\LONGFI~1.TXT
>c:\MYDIRE~2\SUBDIR~2\LONGFI~1.TXT
>c:\FOOBAR\ONETWO~1.TXT

>I think the only correct way to do this  is to execute and analyze a system
>DIR  for each row..
>using  AWK, SED, or PERL

You can certainly do it as you say by doing a "dir fn" for each fn and then
parsing what comes back, using any of the standard tools.

However, I'm going to break my own rule about off-topic posts and suggest
that you look into one of the JP Software command interpreters - i.e., 4DOS,
4NT, or Take Command.  Personally, my choice is Take Command, which blends
nicely the attractiveness of a GUI with the power of a command line.  Since,
presumably, what you are doing is going to be inside some kind of batch
script anyway, you will probably find the increased power of the JP Soft
interpreters useful in other ways.


If this is a one-shot deal, it might be worth downloading it just for this.
(http://www.jpsoft.com)



Sat, 08 Feb 2003 03:00:00 GMT  
 long-to-short dir/filenames


Quote:

>format filenames for input

>the problem is that I have this filelist.txt  with LONG dir/filenames,
>like:

>c:\mydirectorya\subdirectorya\longfilename.txt
>c:\mydirectoryb\subdirectoryb\longfilenameb.txt
>c:\foobar\onetwothree.txt


...
>I think the only correct way to do this  is to execute and analyze a
>system DIR  for each row..
>using  AWK, SED, or PERL
>anyone knows how to do it?

>I'm on Windows 2000,
>w2k has   DIR /X for displaying SFN
>w98 display SFN with a normal DIR
>but both seems to not display the dir shortnames (perhaps you can see
>them by executing a DIR for each dir/subdir in the row.. but I think
>it's a bad method)

It may be a bad method, but short of writing a C program making the
appopriate Windows API call to return the full SFN pathname for a given
LFN pathname, I don't know of any alternative.

This can be done, albeit slowly, with gawk (tested under NT4 SP5).

BEGIN { IGNORECASE = 1 }
{
  gsub(/^ *"|" *$/, "")
  n = split($0, lvl, "\\\\") # yes, 4 backslashes
  if (n == 1) {
    print
  } else {
    pn = lvl[1]
    s = ""
    for (m = 1; m < n; ++m) {
      s = s lvl[m] "\\"
      t = lvl[m + 1]
      cmd = "cmd /c dir /x \"" s t "*\""
      while ((cmd | getline) > 0) {
        if ($0 ~ " " t " *$") pn = pn "\\" $4
      }
      close(cmd)
    }
    print pn
  }

Quote:
}

There may be a direct way to do this, but better places to ask would be
alt.msdos.batch and alt.msdos.batch.nt .

Sent via Deja.com http://www.deja.com/
Before you buy.



Sat, 08 Feb 2003 03:00:00 GMT  
 long-to-short dir/filenames

filenames for input

the problem is that I have this filelist.txt  with LONG dir/filenames,
like:

c:\mydirectorya\subdirectorya\longfilename.txt
c:\mydirectoryb\subdirectoryb\longfilenameb.txt
c:\foobar\onetwothree.txt


c:\MYDIRE~1\SUBDIR~1\LONGFI~1.TXT
c:\MYDIRE~2\SUBDIR~2\LONGFI~1.TXT
c:\FOOBAR\ONETWO~1.TXT

I think the only correct way to do this  is to execute and analyze a system
DIR  for each row..
using  AWK, SED, or PERL  and eventually a BAT file for speed (i.e. instead
of calling many times the "system" command in AWK)
anyone knows how to do it?

I'm on Windows 2000,
w2k has   DIR /X for displaying SFN
w98 display SFN with a normal DIR
but both seems to not display the dir shortnames (perhaps you can see them
by executing a DIR for each dir/subdir in the row.. but I think it's a bad
method)



Sat, 08 Feb 2003 03:00:00 GMT  
 long-to-short dir/filenames


Quote:

>format filenames for input

>the problem is that I have this filelist.txt  with LONG dir/filenames,
>like:

>c:\mydirectorya\subdirectorya\longfilename.txt
>c:\mydirectoryb\subdirectoryb\longfilenameb.txt
>c:\foobar\onetwothree.txt



<snip>

Quote:
>I'm on Windows 2000,
>w2k has   DIR /X for displaying SFN
>w98 display SFN with a normal DIR
>but both seems to not display the dir shortnames (perhaps you can see
>them by executing a DIR for each dir/subdir in the row.. but I think
>it's a bad method)

Awk is not your friend here. Neither is sed. Perl accessing COM objects
would be a much better fit. The following VB Script could be easily
translated into perl. [Pick a language, any language, and include it in
comp.lang.awk.anything-goes.]

'---- begin VBS ----
dim fso, infile, outfile

set fso = CreateObject("Scripting.FileSystemObject")

set infile = fso.OpenTextFile("d:\temp\filelist.lst", 1)
set outfile = fso.OpenTextFile("d:\temp\newflist.lst", 2, True)

do while not infile.AtEndOfStream
  outfile.WriteLine fso.GetFile(infile.ReadLine).ShortPath
loop

infile.Close
outfile.Close
'---  end VBS  ----

Perl could handle both infile and outfile as plain text files with
standard perl i/o. However, the ShortPath property of a Windows
Scripting Host File object should be the most expedient way to get the
8-dot-3 full pathname.

Note: almost certainly you have the Windows Scripting Host installed.
If not, it's a free download from Microsoft's web site.

Sent via Deja.com http://www.deja.com/
Before you buy.



Sat, 08 Feb 2003 03:00:00 GMT  
 long-to-short dir/filenames
[followups limited to comp.lang.perl.misc]


: filenames for input
:
: the problem is that I have this filelist.txt  with LONG dir/filenames,
: like:
:
: c:\mydirectorya\subdirectorya\longfilename.txt
: c:\mydirectoryb\subdirectoryb\longfilenameb.txt
: c:\foobar\onetwothree.txt
:
:

:
: c:\MYDIRE~1\SUBDIR~1\LONGFI~1.TXT
: c:\MYDIRE~2\SUBDIR~2\LONGFI~1.TXT
: c:\FOOBAR\ONETWO~1.TXT

[snip]

: I'm on Windows 2000,

Very easy in Perl [UNTESTED CODE]:

#!perl -wi.bak
use strict;
use Win32;
while (<>) {
  chomp;
  print Win32::GetShortPathName($_),"\n";

Quote:
}



Sat, 08 Feb 2003 03:00:00 GMT  
 long-to-short dir/filenames

Quote:


>yes, I heard of it
>but the problem is: how can I execute function  at the 4DOS prompt?  in a
>brief search in 4dos help and on the web  I didn't find it...

Well, I am assuming that, somewhere in your execution chain, there is a
DOS/Windows/NT/whatever-MS-isCallingItThisWeek batch file.  That batch file
could just as easily be written for 4DOS/etc as for COMMAND or CMD.

I'm not really sure what you mean by "how can I execute function  at the
4DOS prompt?"

Quote:
>what do you think about Harlan full-awk solution compared to the 4DOS
>function?

On this occasion, I agree with most of the posters that doing it by parsing
the output of "dir" is a distinctly "2nd best" approach.  You really want to
be doing it in some tool that has direct access to the OS so that you can
make the OS do the work for you.  4DOS, Perl, VBasic, etc, all meet this
requirement.


Sat, 08 Feb 2003 03:00:00 GMT  
 long-to-short dir/filenames
[followups limited to comp.lang.perl.misc]


: filenames for input
:
: the problem is that I have this filelist.txt  with LONG dir/filenames,
: like:
:
: c:\mydirectorya\subdirectorya\longfilename.txt
: c:\mydirectoryb\subdirectoryb\longfilenameb.txt
: c:\foobar\onetwothree.txt
:
:

:
: c:\MYDIRE~1\SUBDIR~1\LONGFI~1.TXT
: c:\MYDIRE~2\SUBDIR~2\LONGFI~1.TXT
: c:\FOOBAR\ONETWO~1.TXT

[snip]

: I'm on Windows 2000,

Very easy in Perl [UNTESTED CODE]:

#!perl -wi.bak
use strict;
use Win32;
while (<>) {
  chomp;
  print Win32::GetShortPathName($_),"\n";

Quote:
}



Sat, 08 Feb 2003 03:00:00 GMT  
 long-to-short dir/filenames
Harlan, you're a god! I don't have words :)
Quote:
> This can be done, albeit slowly, with gawk (tested under NT4 SP5).

> BEGIN { IGNORECASE = 1 }
> {
>   gsub(/^ *"|" *$/, "")
>   n = split($0, lvl, "\\\\") # yes, 4 backslashes
>   if (n == 1) {
>     print
>   } else {
>     pn = lvl[1]
>     s = ""
>     for (m = 1; m < n; ++m) {
>       s = s lvl[m] "\\"
>       t = lvl[m + 1]
>       cmd = "cmd /c dir /x \"" s t "*\""
>       while ((cmd | getline) > 0) {
>         if ($0 ~ " " t " *$") pn = pn "\\" $4
>       }
>       close(cmd)
>     }
>     print pn
>   }
> }

> There may be a direct way to do this, but better places to ask would be
> alt.msdos.batch and alt.msdos.batch.nt .



Sun, 09 Feb 2003 06:45:52 GMT  
 long-to-short dir/filenames

yes, I heard of it
but the problem is: how can I execute function  at the 4DOS prompt?  in a
brief search in 4dos help and on the web  I didn't find it...

what do you think about Harlan full-awk solution compared to the 4DOS
function?



Sun, 09 Feb 2003 06:50:22 GMT  
 long-to-short dir/filenames
great!! this Perl script works and it's TENS times more fast than the AWK
not-native solution!
Quote:
> use strict;
> use Win32;
> while (<>) {
>   chomp;
>   print Win32::GetShortPathName($_),"\n";
> }



Sun, 09 Feb 2003 03:00:00 GMT  
 long-to-short dir/filenames

Quote:

> great!! this Perl script works and it's TENS times more fast than the
> AWK not-native solution!

The Win32::GetShortPathName() function is a core extension written
in C and included in Perl itself on Win32. Because it's a core
function, the "use Win32" statement is not required.

Quote:
> > use strict;
> > use Win32;
> > while (<>) {
> >   chomp;
> >   print Win32::GetShortPathName($_),"\n";
> > }

This script could actually be shortened to;

    #!perl -wlp
    $_ = Win32::GetShortPathName $_

Here's a demonstration (ActiveState Perl run under the MKS KornShell):

C:/>cat spn.pl
#!perl -wlp
$_ = Win32::GetShortPathName $_
C:/>cmd /c dir /a:d /b /s | egrep ' ' | tail | spn.pl
C:\PROGRA~1\POWERQ~1\PARTIT~1\RESCUEME
C:\PROGRA~1\POWERQ~1\PARTIT~1\UTILITY\DOS
C:\PROGRA~1\POWERQ~1\PARTIT~1\UTILITY\NT
C:\PROGRA~1\POWERQ~1\PARTIT~1\UTILITY\MMOVER32
C:\PROGRA~1\POWERQ~1\PARTIT~1\RESCUEME\IMAGES
C:\PROGRA~1\POWERQ~1\PARTIT~1\RESCUEME\RESCUE
C:\PROGRA~1\ACDSee32\SHORTC~1
C:\PROGRA~1\MarkVis\WinNT
C:\MULTIM~1\Music
C:\MULTIM~1\Music\INTERA~1
C:/>cmd /c dir /a:d /b /s | egrep ' ' | tail

Quote:
> perl -wlpe '$_ = Win32::GetShortPathName $_'

C:\PROGRA~1\POWERQ~1\PARTIT~1\RESCUEME
C:\PROGRA~1\POWERQ~1\PARTIT~1\UTILITY\DOS
C:\PROGRA~1\POWERQ~1\PARTIT~1\UTILITY\NT
C:\PROGRA~1\POWERQ~1\PARTIT~1\UTILITY\MMOVER32
C:\PROGRA~1\POWERQ~1\PARTIT~1\RESCUEME\IMAGES
C:\PROGRA~1\POWERQ~1\PARTIT~1\RESCUEME\RESCUE
C:\PROGRA~1\ACDSee32\SHORTC~1
C:\PROGRA~1\MarkVis\WinNT
C:\MULTIM~1\Music
C:\MULTIM~1\Music\INTERA~1
C:/>

--
Jim Monty

Tempe, Arizona USA



Sun, 09 Feb 2003 03:00:00 GMT  
 long-to-short dir/filenames


Quote:

>> great!! this Perl script works and it's TENS times more fast than the
>> AWK not-native solution!

>The Win32::GetShortPathName() function is a core extension written
>in C and included in Perl itself on Win32. Because it's a core
>function, the "use Win32" statement is not required.

Did you forget which newsgroup this is, again?


Sun, 09 Feb 2003 03:00:00 GMT  
 long-to-short dir/filenames

Quote:

> I'm going to break my own rule about off-topic posts and suggest
> that you look into one of the JP Software command interpreters -
> i.e., 4DOS, 4NT, or Take Command. Personally, my choice is Take
> Command, which blends nicely the attractiveness of a GUI with the
> power of a command line. Since, presumably, what you are doing is
> going to be inside some kind of batch script anyway, you will
> probably find the increased power of the JP Soft interpreters useful
> in other ways.


> If this is a one-shot deal, it might be worth downloading it just
> for this. (http://www.jpsoft.com)

> [...]

> On this occasion, I agree with most of the posters that doing it
> by parsing the output of "dir" is a distinctly "2nd best" approach.
> You really want to be doing it in some tool that has direct access
> to the OS so that you can make the OS do the work for you. 4DOS,
> Perl, VBasic, etc, all meet this requirement.



> > > great!! this Perl script works and it's TENS times more fast than
> > > the AWK not-native solution!

> > The Win32::GetShortPathName() function is a core extension written
> > in C and included in Perl itself on Win32. Because it's a core
> > function, the "use Win32" statement is not required.

> Did you forget which newsgroup this is, again?

Nope. But I did marvel at your shameless hypocrisy and unabashed
self-contradiction, again.

You recommended Perl. Just so we're clear on your opinion: Is Perl
the handiwork of Lucifer and the embodiment of all that is evil in
the world, or is it a viable programming language alternative to
awk that fits neatly and naturally beside awk in any good programmer's
toolbox?

--
Jim Monty

Tempe, Arizona USA           Sauce to the goose is sauce to the gander.



Mon, 10 Feb 2003 03:00:00 GMT  
 long-to-short dir/filenames

Quote:

> I'm going to break my own rule about off-topic posts and suggest
> that you look into one of the JP Software command interpreters -
> i.e., 4DOS, 4NT, or Take Command. Personally, my choice is Take
> Command, which blends nicely the attractiveness of a GUI with the
> power of a command line. Since, presumably, what you are doing is
> going to be inside some kind of batch script anyway, you will
> probably find the increased power of the JP Soft interpreters useful
> in other ways.


> If this is a one-shot deal, it might be worth downloading it just
> for this. (http://www.jpsoft.com)

> [...]

> On this occasion, I agree with most of the posters that doing it
> by parsing the output of "dir" is a distinctly "2nd best" approach.
> You really want to be doing it in some tool that has direct access
> to the OS so that you can make the OS do the work for you. 4DOS,
> Perl, VBasic, etc, all meet this requirement.



> > > great!! this Perl script works and it's TENS times more fast than
> > > the AWK not-native solution!

> > The Win32::GetShortPathName() function is a core extension written
> > in C and included in Perl itself on Win32. Because it's a core
> > function, the "use Win32" statement is not required.

> Did you forget which newsgroup this is, again?

Nope. But I did marvel at your shameless hypocrisy and unabashed
self-contradiction, again.

You recommended Perl. Just so we're clear on your opinion: Is Perl
the handiwork of Lucifer and the embodiment of all that is evil in
the world, or is it a viable programming language alternative to
awk that fits neatly and naturally beside awk in any good programmer's
toolbox?

--
Jim Monty

Tempe, Arizona USA           Sauce to the goose is sauce to the gander.



Mon, 10 Feb 2003 03:00:00 GMT  
 
 [ 22 post ]  Go to page: [1] [2]

 Relevant Pages 

1. long = short*short ; (short,short) = long/short

2. Dir[] on Windows w/ long filenames

3. win32api -- long vs short filenames

4. Long Filenames okay for physical filenames???

5. DOS 8.3 filenames (how to remove long filenames header)

6. Library os.path.isfile(filename) - long filenames error.

7. Getting "Short" filenames inWindows

8. Osx long filenames truncated

9. VW2.0 under Win 95 + long filenames?

10. Long Filenames

11. Spaces in Directory Names - Long Filenames

12. Long Filenames in Clarion

 

 
Powered by phpBB® Forum Software