---------- Forwarded message ----------
From: Adin Burroughs <adindb@gmail.com>
Date: May 9, 2005 1:12 AM
Subject: Filename Globbing issues on Win32?
To: bug-coreutils@gnu.org
OK, first off, I'm on Win32 (XP) using 5.3 of coreutils.
I have been knocking my head on this and I'm feeling really stupid.
I swear, I'm unix literate, but I can't seem to get the following to
work without cheating:
cp -uvp "c:\dir with space\long path*" k:\path
or
cp -uvp "c:\dir with space\long path"* k:\path
I call this "cheating": (though it works)
cp -uvp c:\dirwit~1\longpa~1* l:\path
this also works:
cp -uvp "c:\dir with space\long path\filename" k:\path
The problem seems to crop up when using wildcards in a path enclosed
by quotes. The exact error that cp gives is that it can't stat the
path, so it's an invalid argument.(it does echo back the escaped path
-- c:\dir with space\long path\*)
I haven't been able to find much of anything in the documentation that
specifically addresses the windows implementation...and I didn't see
anything in the bug archives.
Am I missing something really obvious, or have I tripped across an
old bug? (this behavior is consistent with coreutils 5.2.1 and the
older fileutils versions).
The guys over at the gnu coreutils list think its a bug in the GnuWin32 implementation of coreutils....is there anything specific to the windows shell to take care of filename globbing?
Thanks in advance!
-adin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The MS-Windows way of globbing is described at MSDN: http://msdn.microsoft.com/library/en-us/vclang/html/pluslang_Parsing_C.2b2b.Command.2d.Line_Arguments.asp
From this description it seems that your example should work; also native commands, such as dir, do expand the * when inside quotes. So possibly this behaviour of cp and other coreutils programs, is a bug, either in the Gnuwin32 port or in some system library, such as msvcrt.dll.
Other MS-Windows ports, such as Cygwin, Djgpp and Unixutils, have the same behaviour, so I suspect it is a bug of some system library.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It is not true that DJGPP behaves like the original poster reported. DJGPP programs expand wildcards outside quotes, even if the rest of the argument is inside quotes. That is, "c:\dir with spaces\"* would cause the spaces to be preserved and the * to be expanded, as you'd expect. OTOH, "c:\dir with spaces*" will leave * unexpanded, again as expected. (The latter behavior is required for programs like Find which want to expand the wildcards themselves.)
However, it is not interesting to compare MinGW behavior with DJGPP behavior, since DJGPP has its own globbing code which emulates Posix behavior much closer than Microsoft runtime, e.g. it supports wildcards like *.[ch] etc.
To the original poster: did you try to use forward slashes instead of backslashes? Like this:
cp -uvp "c:/dir with space/long path"/* k:/path
I'm thinking that perhaps the backslash causes the * to be taken literally for some reason.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Forward slashes & moving the slash & asterisk outside the quotes doesn't work. Examples below...
-adin
C:\Documents and Settings\Adn>cp -uvp c:/Program Files/Sony Handheld/adn/sunri
se/slot0/ k:/palm/programs/plucker
cp: cannot stat c:/Program': No such file or directory
cp: cannot statFiles/Sony': No such file or directory
cp: cannot stat `Handheld/adn/sunrise/slot0/': No such file or directory
C:\Documents and Settings\Adn>cp -uvp "c:/Program Files/Sony Handheld/adn/sunr
ise/slot0"/ k:/palm/programs/plucker
cp: cannot stat `c:/Program Files/Sony Handheld/adn/sunrise/slot0/': Invalid a
rgument
C:\Documents and Settings\Adn>cp -uvp "c:/Program Files/Sony Handheld/adn/sunr
ise/slot0/" k:/palm/programs/plucker
cp: cannot stat `c:/Program Files/Sony Handheld/adn/sunrise/slot0/': Invalid a
rgument
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
And here are some additional command line examples: (moving quotes around):
And moving the asterisk outside the quotes didn't work: (ok, actual
examples from the commandline this time)
<quote>
C:\Documents and Settings\Adn>cp "c:\Program Files\Sony Handheld\adn\sunrise\s
lot0\"* k:\palm\PROGRAMS\plucker
cp: missing destination file operand after c:\\Program Files\\Sony Handheld\\ad
n\\sunrise\\slot0"* k:\\palm\\PROGRAMS\\plucker'
Trycp --help' for more information.
C:\Documents and Settings\Adn>cp "c:\Program Files\Sony Handheld\adn\sunrise\s
lot0"* k:\palm\PROGRAMS\plucker
cp: cannot stat `c:\Program Files\Sony Handheld\adn\sunrise\slot0\*': Inv
alid argument
C:\Documents and Settings\Adn>cp --version
cp (GNU coreutils) 5.3.0
Written by Torbjorn Granlund, David MacKenzie, and Jim Meyering.
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
---------- Forwarded message ----------
From: Adin Burroughs <adindb@gmail.com>
Date: May 9, 2005 1:12 AM
Subject: Filename Globbing issues on Win32?
To: bug-coreutils@gnu.org
OK, first off, I'm on Win32 (XP) using 5.3 of coreutils.
I have been knocking my head on this and I'm feeling really stupid.
I swear, I'm unix literate, but I can't seem to get the following to
work without cheating:
cp -uvp "c:\dir with space\long path*" k:\path
or
cp -uvp "c:\dir with space\long path"* k:\path
I call this "cheating": (though it works)
cp -uvp c:\dirwit~1\longpa~1* l:\path
this also works:
cp -uvp "c:\dir with space\long path\filename" k:\path
The problem seems to crop up when using wildcards in a path enclosed
by quotes. The exact error that cp gives is that it can't stat the
path, so it's an invalid argument.(it does echo back the escaped path
-- c:\dir with space\long path\*)
I haven't been able to find much of anything in the documentation that
specifically addresses the windows implementation...and I didn't see
anything in the bug archives.
Am I missing something really obvious, or have I tripped across an
old bug? (this behavior is consistent with coreutils 5.2.1 and the
older fileutils versions).
The guys over at the gnu coreutils list think its a bug in the GnuWin32 implementation of coreutils....is there anything specific to the windows shell to take care of filename globbing?
Thanks in advance!
-adin
The MS-Windows way of globbing is described at MSDN: http://msdn.microsoft.com/library/en-us/vclang/html/pluslang_Parsing_C.2b2b.Command.2d.Line_Arguments.asp
From this description it seems that your example should work; also native commands, such as dir, do expand the * when inside quotes. So possibly this behaviour of cp and other coreutils programs, is a bug, either in the Gnuwin32 port or in some system library, such as msvcrt.dll.
Other MS-Windows ports, such as Cygwin, Djgpp and Unixutils, have the same behaviour, so I suspect it is a bug of some system library.
The documentation at MSDN states that wildcard expansion is suppressed within quotes. Although this may be unexpeced, it can therefore be regarded as a feature, not as a bug. See:
http://msdn.microsoft.com/library/en-us/vccelng/htm/progs_11.asp
It is not true that DJGPP behaves like the original poster reported. DJGPP programs expand wildcards outside quotes, even if the rest of the argument is inside quotes. That is, "c:\dir with spaces\"* would cause the spaces to be preserved and the * to be expanded, as you'd expect. OTOH, "c:\dir with spaces*" will leave * unexpanded, again as expected. (The latter behavior is required for programs like Find which want to expand the wildcards themselves.)
However, it is not interesting to compare MinGW behavior with DJGPP behavior, since DJGPP has its own globbing code which emulates Posix behavior much closer than Microsoft runtime, e.g. it supports wildcards like *.[ch] etc.
To the original poster: did you try to use forward slashes instead of backslashes? Like this:
cp -uvp "c:/dir with space/long path"/* k:/path
I'm thinking that perhaps the backslash causes the * to be taken literally for some reason.
Forward slashes & moving the slash & asterisk outside the quotes doesn't work. Examples below...
-adin
C:\Documents and Settings\Adn>cp -uvp c:/Program Files/Sony Handheld/adn/sunri
se/slot0/ k:/palm/programs/plucker
cp: cannot stat
c:/Program': No such file or directory cp: cannot statFiles/Sony': No such file or directorycp: cannot stat `Handheld/adn/sunrise/slot0/': No such file or directory
C:\Documents and Settings\Adn>cp -uvp "c:/Program Files/Sony Handheld/adn/sunr
ise/slot0"/ k:/palm/programs/plucker
cp: cannot stat `c:/Program Files/Sony Handheld/adn/sunrise/slot0/': Invalid a
rgument
C:\Documents and Settings\Adn>cp -uvp "c:/Program Files/Sony Handheld/adn/sunr
ise/slot0/" k:/palm/programs/plucker
cp: cannot stat `c:/Program Files/Sony Handheld/adn/sunrise/slot0/': Invalid a
rgument
The following seems to work:
cp -uvp c:/Program" "Files/Sony Handheld/adn/sunrise/slot0/* k:/palm/programs/plucker
So, quote only the space .
Of course, both spaces should be quoted:
cp -uvp c:/Program" "Files/Sony" "Handheld/adn/sunrise/slot0/* k:/palm/programs/plucker
Works with both forward and back slashes.
Though if the filename has funky characters and backslashes are used, it fails for the file (though filenames with spaces in them come out fine):
C:\Documents and Settings\Adn>cp -uvp c:\Program" "Files\sony" "handheld\adn\s
unrise\slot0* k:\palm\programs\plucker
cp: cannot stat
c:\\Program Files\\sony handheld\\adn\\sunrise\\slot0\\? The J oy of Tech! ?.pdb': Invalid argumentc:\Program Files\sony handheld\adn\sunrise\slot0\[H]ardOCP.pdb' ->k:\\ palm\\programs\\plucker/[H]ardOCP.pdb'c:\Program Files\sony handheld\adn\sunrise\slot0\Burn This! - The FeedBurner Weblog.pdb' ->
k:\\palm\\programs\\plucker/Burn This! - The FeedBurner Web log.pdb'c:\Program Files\sony handheld\adn\sunrise\slot0\C4ISR Headlines.pdb' ->`k:\palm\programs\plucker/C4ISR Headlines.pdb'
Erp, the filename fails out with forward slashes as well as backwards slashes.
I did try it with forward slashes, got errors as well.
And here are some additional command line examples: (moving quotes around):
And moving the asterisk outside the quotes didn't work: (ok, actual
examples from the commandline this time)
<quote>
C:\Documents and Settings\Adn>cp "c:\Program Files\Sony Handheld\adn\sunrise\s
lot0\"* k:\palm\PROGRAMS\plucker
cp: missing destination file operand after
c:\\Program Files\\Sony Handheld\\ad n\\sunrise\\slot0"* k:\\palm\\PROGRAMS\\plucker' Trycp --help' for more information.C:\Documents and Settings\Adn>cp "c:\Program Files\Sony Handheld\adn\sunrise\s
lot0"* k:\palm\PROGRAMS\plucker
cp: cannot stat `c:\Program Files\Sony Handheld\adn\sunrise\slot0\*': Inv
alid argument
C:\Documents and Settings\Adn>cp --version
cp (GNU coreutils) 5.3.0
Written by Torbjorn Granlund, David MacKenzie, and Jim Meyering.
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.