Finding file names with spaces in them

  • Thread starter Thread starter Charles Lavin
  • Start date Start date
C

Charles Lavin

Hi --

How can I find all files within a folder tree that have spaces in the file
name?

Thanks,
CL
 
Charles Lavin said:
Hi --

How can I find all files within a folder tree that have spaces in the file
name?

Thanks,
CL

Try this:
- Start a Command Prompt
- Navigate to the folder you wish to examine
- Type this command:
dir /s /b | find " "
or, if you do NOT with to see folder names with embedded spaces:
dir /s /b /a-d | find " "
 
Hi --

That doesn't quite work. It picks up folders along the way with spaces in
the folder name, even if the files themselves do not. I tried adding an /a-d
switch to dir; the only way it works is if I remove the /s flag. I need to
find only those files within the folders that have spaces in the file names,
and I have thousands of folders to navigate. I don't want to have to do this
folder by folder.

I miss Unix ... Isn't there any tool in Windows that understands regular
expressions when dealing with files?

Thanks for the info,
CL
 
Missing Unix is like telling your new wife that you miss
your divorced wife. She might reply that she's a package
deal: Either you take her as she is or you move on . . .

This batch file will do more or less what you want:

@echo off
for /r %%a in (.) do call :sub %%a
goto :eof

:sub
echo Scanning %*
dir "%*" /b 2>nul | find " "
 
Very elegant. I don't quite understand why it works but I like it!


"David Candy" <.> wrote in message
dir "* ?*.*" /a-d /s /b
 
That worked! Although I'm not sure why ...

Why "* ?*" ? Isn't that "any number of characters, space, any one character,
any number of characters"? I had tried "* *" and that wasn't working. Are
the pattern-matching rules different in the newer generation Windows?

Thanks!

CL

"David Candy" <.> wrote in message
dir "* ?*.*" /a-d /s /b
 
:-)

In this case, I haven't divorced the first wife. The "new wife" is more like
a TV or stage wife -- someone I have to work with because that's what the
script calls for <g> ...

I actually took care of this last night from a Unix workstation, courtesy of
a remote filesystem mount and the Unix "find" command.

But David posted a dir call that looks like it does exactly what I need. But
I'm not sure why it works, unless pattern-matching rules for "?" have
changed in Windows XP.

Thanks for your help,
CL
 
Charles said:
That worked! Although I'm not sure why ...

Why "* ?*" ? Isn't that "any number of characters, space, any one character,
any number of characters"? I had tried "* *" and that wasn't working. Are
the pattern-matching rules different in the newer generation Windows?

As an aside, the ? wildcard will pick up spaces, AND, what "appear" to
be spaces. eg "non-dos" characters which windows or dos will show as a
space if it cant figure out what the actual character is.
 
? is a character - it must exist. * is NONE or more characters. It may have worked without the ?, I didn't try because I learnt long ago to specify ?* which is one or more characters rather than none or more.
 
Aha!

Thanks!


Plato said:
As an aside, the ? wildcard will pick up spaces, AND, what "appear" to
be spaces. eg "non-dos" characters which windows or dos will show as a
space if it cant figure out what the actual character is.
 
Hi --

I'm still confused, though. As far as I remember, "?" is ANY character. The
pattern "* ?*" should pick up any name that has a space and at least one
more character following the space. The pattern "* *" should pick up any
name that has a space and zero or more characters. (Although that would be
an illegal file name...)

I wish Windows would "just do it" and incorporate regular expression
matching ...

Thanks again,
CL

"David Candy" <.> wrote in message
? is a character - it must exist. * is NONE or more characters. It may have
worked without the ?, I didn't try because I learnt long ago to specify ?*
which is one or more characters rather than none or more.
 
It is regular expressions but modified to recognise Dos wildcards. That means I don't know the exact rules as there are implied wildcards from the Dos rules. An example is dir * which is read as *.* for Dos compatability reasons.

Also Dir can take multiple file patterns. Space is a delimiter here so quotes is important (see Dir in Help and Support).

Dir * *

will give two full directory listings one after the other.
--
--------------------------------------------------------------------------------------------------
http://webdiary.smh.com.au/archives/_comment/001075.html
=================================================
Charles Lavin said:
Hi --

I'm still confused, though. As far as I remember, "?" is ANY character. The
pattern "* ?*" should pick up any name that has a space and at least one
more character following the space. The pattern "* *" should pick up any
name that has a space and zero or more characters. (Although that would be
an illegal file name...)

I wish Windows would "just do it" and incorporate regular expression
matching ...

Thanks again,
CL

"David Candy" <.> wrote in message
? is a character - it must exist. * is NONE or more characters. It may have
worked without the ?, I didn't try because I learnt long ago to specify ?*
which is one or more characters rather than none or more.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top