public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* RE: Obtaining short DOS file names?
@ 2000-05-31 13:23 Paul Stodghill
  0 siblings, 0 replies; 8+ messages in thread
From: Paul Stodghill @ 2000-05-31 13:23 UTC (permalink / raw)
  To: 'cygwin@sourceware.cygnus.com'

Chris wrote,
> There is no cygwin-specific way of getting the short file 
> name.  The concept
> has no meaning on UNIX.  There are Windows programs available 
> which do this.
> 'dir' is one of them, for instance.

Gotcha. I can hack something up from this.

> Is there some reason why quoting the filename doesn't work?

It would, but it will take me a while to track down all of the places that
the scripts are broken. I'm looking for something quick and dirty to get
going.

Thanks.

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Obtaining short DOS file names?
@ 2000-06-07  5:38 Paul Stodghill
  0 siblings, 0 replies; 8+ messages in thread
From: Paul Stodghill @ 2000-06-07  5:38 UTC (permalink / raw)
  To: 'cygwin@sourceware.cygnus.com'

Ok, this version works. It's faster than my script, but my version shortens
the entire full file name. 

> -----Original Message-----
> From: Barry Buchbinder [ mailto:BBUCHBINDER@niaid.nih.gov ]
> Sent: Tuesday, June 06, 2000 3:40 PM
> To: 'cygwin@sourceware.cygnus.com'
> Subject: RE: Obtaining short DOS file names?
> 
> 
> The output of dir is different in command.com and cmd.exe.  
> In a version I
> have of cmd.exe compiled for win9x, the following works for me.
> 
> function sfn() {
>   win95cmd /c dir /x "$1" | \
>     sed -e '/^ /d' \
>       -e 's/^......................................//' \
>       -e 's/^ *//' -e 's/ .*//'
>   }
> 
> You might have to play with the options to dir and with the 
> sed processing
> to get it to work for Win2k.
> 
> - Barry
> 
>  -----Original Message-----
> 
>      To: "'cygwin at sourceware dot cygnus dot com'" <cygwin 
> at sourceware
> dot cygnus dot com> 
>      Subject: RE: Obtaining short DOS file names? 
>      From: Paul Stodghill <stodghil at cs dot cornell dot edu> 
>      Date: Tue, 6 Jun 2000 13:19:38 -0400 
> 
> This doesn't work under Win2k. First, it doesn't like 
> "command.com". After
> changing that to "cmd", it just prints the date when the first was
> modified... 
> 
> > -----Original Message-----
> > From: Barry Buchbinder [ mailto:BBUCHBINDER@niaid.nih.gov ]
> > Sent: Tuesday, June 06, 2000 12:43 PM
> > To: 'cygwin@sourceware.cygnus.com'
> > Subject: RE: Obtaining short DOS file names?
> > 
> > 
> > This works on Win98.
> > 
> > Try putting this function in .bashrc
> > 
> > function sfn() {
> >       command.com /c dir "$1" | sed -e '/^ /d' -e 
> > 's/^............/&^G/'
> > -e 's/^G.*$//' -e 's/ *$//' -e 's/  */\./'
> >       }
> > 
> > (Note: "^G" is a control-G/bell, which I don't expect to 
> find in a DOS
> > filename.)
> > 
> > Then if you just want a list, you can do the following
> >       $ sfn dos_file_spec
> > If you want to feed the list to a program, do
> >       $ prog `sfn dos_file_spec`
> > Remember to quote or escape anything that bash might expand.
> > 
> > Command.com must have the ".com" typed.  I'm not sure that it 
> > will work or
> > can be easily adapted for cmd.exe.  sfn takes a single argument.
> > 
> > It's ugly and slow, but it works for me.  Excuse me if my sed 
> > programming
> > was less than elegant.
> > 
> > - Barry Buchbinder
> > 
> >  -----Original Message-----
> > I've attached a Perl script that converts long file names to 
> > short file
> > names. Hope that some else finds this useful.
> > 
> > milhouse% perl shorten.pl  '/cygdrive/c/Program 
> > Files/Microsoft Visual \
> > Studio/VIntDev98/ScriptLibrary/RECORDSET.HTM'
> > /cygdrive/c/PROGRA~1/MICROS~4/VINTDE~1/SCRIPT~1/RECORD~1.HTM
> > milhouse% 
> > 
> > > -----Original Message-----
> > > From: Paul Stodghill [ mailto:stodghil@CS.Cornell.EDU ]
> > > Sent: Wednesday, May 31, 2000 10:38 AM
> > > To: 'cygwin@sourceware.cygnus.com'
> > > Subject: RE: Obtaining short DOS file names?
> > > 
> > > 
> > > Chris wrote,
> > > > There is no cygwin-specific way of getting the short file 
> > > > name.  The concept
> > > > has no meaning on UNIX.  There are Windows programs available 
> > > > which do this.
> > > > 'dir' is one of them, for instance.
> > > 
> > > Gotcha. I can hack something up from this.
> > > 
> > > > Is there some reason why quoting the filename doesn't work?
> > > 
> > > It would, but it will take me a while to track down all of 
> > > the places that
> > > the scripts are broken. I'm looking for something quick and 
> > > dirty to get
> > > going.
> > > 
> > > Thanks.
> 
> --
> Want to unsubscribe from this list?
> Send a message to cygwin-unsubscribe@sourceware.cygnus.com
> 

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Obtaining short DOS file names?
@ 2000-06-06 12:44 Barry Buchbinder
  0 siblings, 0 replies; 8+ messages in thread
From: Barry Buchbinder @ 2000-06-06 12:44 UTC (permalink / raw)
  To: 'cygwin@sourceware.cygnus.com'

The output of dir is different in command.com and cmd.exe.  In a version I
have of cmd.exe compiled for win9x, the following works for me.

function sfn() {
  win95cmd /c dir /x "$1" | \
    sed -e '/^ /d' \
      -e 's/^......................................//' \
      -e 's/^ *//' -e 's/ .*//'
  }

You might have to play with the options to dir and with the sed processing
to get it to work for Win2k.

- Barry

 -----Original Message-----

     To: "'cygwin at sourceware dot cygnus dot com'" <cygwin at sourceware
dot cygnus dot com> 
     Subject: RE: Obtaining short DOS file names? 
     From: Paul Stodghill <stodghil at cs dot cornell dot edu> 
     Date: Tue, 6 Jun 2000 13:19:38 -0400 

This doesn't work under Win2k. First, it doesn't like "command.com". After
changing that to "cmd", it just prints the date when the first was
modified... 

> -----Original Message-----
> From: Barry Buchbinder [ mailto:BBUCHBINDER@niaid.nih.gov ]
> Sent: Tuesday, June 06, 2000 12:43 PM
> To: 'cygwin@sourceware.cygnus.com'
> Subject: RE: Obtaining short DOS file names?
> 
> 
> This works on Win98.
> 
> Try putting this function in .bashrc
> 
> function sfn() {
>       command.com /c dir "$1" | sed -e '/^ /d' -e 
> 's/^............/&^G/'
> -e 's/^G.*$//' -e 's/ *$//' -e 's/  */\./'
>       }
> 
> (Note: "^G" is a control-G/bell, which I don't expect to find in a DOS
> filename.)
> 
> Then if you just want a list, you can do the following
>       $ sfn dos_file_spec
> If you want to feed the list to a program, do
>       $ prog `sfn dos_file_spec`
> Remember to quote or escape anything that bash might expand.
> 
> Command.com must have the ".com" typed.  I'm not sure that it 
> will work or
> can be easily adapted for cmd.exe.  sfn takes a single argument.
> 
> It's ugly and slow, but it works for me.  Excuse me if my sed 
> programming
> was less than elegant.
> 
> - Barry Buchbinder
> 
>  -----Original Message-----
> I've attached a Perl script that converts long file names to 
> short file
> names. Hope that some else finds this useful.
> 
> milhouse% perl shorten.pl  '/cygdrive/c/Program 
> Files/Microsoft Visual \
> Studio/VIntDev98/ScriptLibrary/RECORDSET.HTM'
> /cygdrive/c/PROGRA~1/MICROS~4/VINTDE~1/SCRIPT~1/RECORD~1.HTM
> milhouse% 
> 
> > -----Original Message-----
> > From: Paul Stodghill [ mailto:stodghil@CS.Cornell.EDU ]
> > Sent: Wednesday, May 31, 2000 10:38 AM
> > To: 'cygwin@sourceware.cygnus.com'
> > Subject: RE: Obtaining short DOS file names?
> > 
> > 
> > Chris wrote,
> > > There is no cygwin-specific way of getting the short file 
> > > name.  The concept
> > > has no meaning on UNIX.  There are Windows programs available 
> > > which do this.
> > > 'dir' is one of them, for instance.
> > 
> > Gotcha. I can hack something up from this.
> > 
> > > Is there some reason why quoting the filename doesn't work?
> > 
> > It would, but it will take me a while to track down all of 
> > the places that
> > the scripts are broken. I'm looking for something quick and 
> > dirty to get
> > going.
> > 
> > Thanks.

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Obtaining short DOS file names?
@ 2000-06-06 11:05 Paul Stodghill
  0 siblings, 0 replies; 8+ messages in thread
From: Paul Stodghill @ 2000-06-06 11:05 UTC (permalink / raw)
  To: 'cygwin@sourceware.cygnus.com'

This doesn't work under Win2k. First, it doesn't like "command.com". After
changing that to "cmd", it just prints the date when the first was
modified... 

> -----Original Message-----
> From: Barry Buchbinder [ mailto:BBUCHBINDER@niaid.nih.gov ]
> Sent: Tuesday, June 06, 2000 12:43 PM
> To: 'cygwin@sourceware.cygnus.com'
> Subject: RE: Obtaining short DOS file names?
> 
> 
> This works on Win98.
> 
> Try putting this function in .bashrc
> 
> function sfn() {
> 	command.com /c dir "$1" | sed -e '/^ /d' -e 
> 's/^............/&^G/'
> -e 's/^G.*$//' -e 's/ *$//' -e 's/  */\./'
> 	}
> 
> (Note: "^G" is a control-G/bell, which I don't expect to find in a DOS
> filename.)
> 
> Then if you just want a list, you can do the following
> 	$ sfn dos_file_spec
> If you want to feed the list to a program, do
> 	$ prog `sfn dos_file_spec`
> Remember to quote or escape anything that bash might expand.
> 
> Command.com must have the ".com" typed.  I'm not sure that it 
> will work or
> can be easily adapted for cmd.exe.  sfn takes a single argument.
> 
> It's ugly and slow, but it works for me.  Excuse me if my sed 
> programming
> was less than elegant.
> 
> - Barry Buchbinder
> 
>  -----Original Message-----
> I've attached a Perl script that converts long file names to 
> short file
> names. Hope that some else finds this useful.
> 
> milhouse% perl shorten.pl  '/cygdrive/c/Program 
> Files/Microsoft Visual \
> Studio/VIntDev98/ScriptLibrary/RECORDSET.HTM'
> /cygdrive/c/PROGRA~1/MICROS~4/VINTDE~1/SCRIPT~1/RECORD~1.HTM
> milhouse% 
> 
> > -----Original Message-----
> > From: Paul Stodghill [ mailto:stodghil@CS.Cornell.EDU ]
> > Sent: Wednesday, May 31, 2000 10:38 AM
> > To: 'cygwin@sourceware.cygnus.com'
> > Subject: RE: Obtaining short DOS file names?
> > 
> > 
> > Chris wrote,
> > > There is no cygwin-specific way of getting the short file 
> > > name.  The concept
> > > has no meaning on UNIX.  There are Windows programs available 
> > > which do this.
> > > 'dir' is one of them, for instance.
> > 
> > Gotcha. I can hack something up from this.
> > 
> > > Is there some reason why quoting the filename doesn't work?
> > 
> > It would, but it will take me a while to track down all of 
> > the places that
> > the scripts are broken. I'm looking for something quick and 
> > dirty to get
> > going.
> > 
> > Thanks.
> 
> --
> Want to unsubscribe from this list?
> Send a message to cygwin-unsubscribe@sourceware.cygnus.com
> 

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Obtaining short DOS file names?
@ 2000-06-06  9:47 Barry Buchbinder
  0 siblings, 0 replies; 8+ messages in thread
From: Barry Buchbinder @ 2000-06-06  9:47 UTC (permalink / raw)
  To: 'cygwin@sourceware.cygnus.com'

This works on Win98.

Try putting this function in .bashrc

function sfn() {
	command.com /c dir "$1" | sed -e '/^ /d' -e 's/^............/&^G/'
-e 's/^G.*$//' -e 's/ *$//' -e 's/  */\./'
	}

(Note: "^G" is a control-G/bell, which I don't expect to find in a DOS
filename.)

Then if you just want a list, you can do the following
	$ sfn dos_file_spec
If you want to feed the list to a program, do
	$ prog `sfn dos_file_spec`
Remember to quote or escape anything that bash might expand.

Command.com must have the ".com" typed.  I'm not sure that it will work or
can be easily adapted for cmd.exe.  sfn takes a single argument.

It's ugly and slow, but it works for me.  Excuse me if my sed programming
was less than elegant.

- Barry Buchbinder

 -----Original Message-----
I've attached a Perl script that converts long file names to short file
names. Hope that some else finds this useful.

milhouse% perl shorten.pl  '/cygdrive/c/Program Files/Microsoft Visual \
Studio/VIntDev98/ScriptLibrary/RECORDSET.HTM'
/cygdrive/c/PROGRA~1/MICROS~4/VINTDE~1/SCRIPT~1/RECORD~1.HTM
milhouse% 

> -----Original Message-----
> From: Paul Stodghill [ mailto:stodghil@CS.Cornell.EDU ]
> Sent: Wednesday, May 31, 2000 10:38 AM
> To: 'cygwin@sourceware.cygnus.com'
> Subject: RE: Obtaining short DOS file names?
> 
> 
> Chris wrote,
> > There is no cygwin-specific way of getting the short file 
> > name.  The concept
> > has no meaning on UNIX.  There are Windows programs available 
> > which do this.
> > 'dir' is one of them, for instance.
> 
> Gotcha. I can hack something up from this.
> 
> > Is there some reason why quoting the filename doesn't work?
> 
> It would, but it will take me a while to track down all of 
> the places that
> the scripts are broken. I'm looking for something quick and 
> dirty to get
> going.
> 
> Thanks.

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Obtaining short DOS file names?
@ 2000-06-06  7:45 Paul Stodghill
  0 siblings, 0 replies; 8+ messages in thread
From: Paul Stodghill @ 2000-06-06  7:45 UTC (permalink / raw)
  To: 'cygwin@sourceware.cygnus.com'

[-- Attachment #1: Type: text/plain, Size: 1166 bytes --]

I've attached a Perl script that converts long file names to short file
names. Hope that some else finds this useful.


milhouse% perl shorten.pl  '/cygdrive/c/Program Files/Microsoft Visual \
Studio/VIntDev98/ScriptLibrary/RECORDSET.HTM'
/cygdrive/c/PROGRA~1/MICROS~4/VINTDE~1/SCRIPT~1/RECORD~1.HTM
milhouse% 

> -----Original Message-----
> From: Paul Stodghill [ mailto:stodghil@CS.Cornell.EDU ]
> Sent: Wednesday, May 31, 2000 10:38 AM
> To: 'cygwin@sourceware.cygnus.com'
> Subject: RE: Obtaining short DOS file names?
> 
> 
> Chris wrote,
> > There is no cygwin-specific way of getting the short file 
> > name.  The concept
> > has no meaning on UNIX.  There are Windows programs available 
> > which do this.
> > 'dir' is one of them, for instance.
> 
> Gotcha. I can hack something up from this.
> 
> > Is there some reason why quoting the filename doesn't work?
> 
> It would, but it will take me a while to track down all of 
> the places that
> the scripts are broken. I'm looking for something quick and 
> dirty to get
> going.
> 
> Thanks.
> 
> --
> Want to unsubscribe from this list?
> Send a message to cygwin-unsubscribe@sourceware.cygnus.com
> 


[-- Attachment #2: shorten.pl --]
[-- Type: text/x-perl, Size: 688 bytes --]

# -*- perl -*-

eval 'exec perl -S $0 ${1+"$@"}'
  if $running_under_some_shell;

$FILE = $ARGV[0];
if ( "$FILE" eq "" ) {
  print "Usage: ntutils/shorten filename" > STDERR;
  exit 1
}
$FILE = `cygpath -w "$FILE"`;
chomp $FILE;
$FILE =~ s|\\|/|g;

@STACK = reverse(split(/\//,$FILE));

$NEWNAME = pop @STACK;

while ( $#STACK >= 0 ) {
  $OLD_FILE = pop @STACK;
  $NEWNAME2 = $NEWNAME;
  $NEWNAME2 =~ s|/|\\|g;
  $NEW_FILE = `cmd /c \"dir /x \\\"$NEWNAME2\\\"\\\\\" | egrep \"$OLD_FILE\"\'$\' | cut -c40-51`;
  chomp $NEW_FILE;
  $NEW_FILE =~ s/ +$//;
  if ( $NEW_FILE eq "" ) { 
    $NEW_FILE = $OLD_FILE; 
  }
  $NEWNAME = $NEWNAME . "/" . $NEW_FILE;
}

print `cygpath -u "$NEWNAME"`;


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Obtaining short DOS file names?
  2000-05-31  7:21 Paul Stodghill
@ 2000-05-31  7:29 ` Chris Faylor
  0 siblings, 0 replies; 8+ messages in thread
From: Chris Faylor @ 2000-05-31  7:29 UTC (permalink / raw)
  To: Cygwin Mailing List (E-mail); +Cc: stodghil

On Wed, May 31, 2000 at 10:21:39AM -0400, Paul Stodghill wrote:
>I'm working with some shell scripts under Cygwin that do not handle spaces
>in file names very well. "No problem," I think, "I'll just use the short
>versions of the file names".
>
>Is there anyway to obtain the short version of a file name from the long
>version within a shell script?

There is no cygwin-specific way of getting the short file name.  The concept
has no meaning on UNIX.  There are Windows programs available which do this.
'dir' is one of them, for instance.

Is there some reason why quoting the filename doesn't work?

cgf

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Obtaining short DOS file names?
@ 2000-05-31  7:21 Paul Stodghill
  2000-05-31  7:29 ` Chris Faylor
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Stodghill @ 2000-05-31  7:21 UTC (permalink / raw)
  To: Cygwin Mailing List (E-mail)

I'm working with some shell scripts under Cygwin that do not handle spaces
in file names very well. "No problem," I think, "I'll just use the short
versions of the file names".

Is there anyway to obtain the short version of a file name from the long
version within a shell script?

E.g.,

		c:\Program Files\Microsoft Visual Studio\ ->
			c:\PROGRA~1\MICROS~4\
	or
		/cygdrive/c/Program Files/Microsoft Visual Studio/ ->
			/cygdrive/c/PROGRA~1/MICROS~4/

Thanks.


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2000-06-07  5:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-31 13:23 Obtaining short DOS file names? Paul Stodghill
  -- strict thread matches above, loose matches on Subject: below --
2000-06-07  5:38 Paul Stodghill
2000-06-06 12:44 Barry Buchbinder
2000-06-06 11:05 Paul Stodghill
2000-06-06  9:47 Barry Buchbinder
2000-06-06  7:45 Paul Stodghill
2000-05-31  7:21 Paul Stodghill
2000-05-31  7:29 ` Chris Faylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).