Re: Renaming files using wildcards

anonymous_at_discussions.microsoft.com
Date: 09/05/04


Date: Sat, 4 Sep 2004 19:22:56 -0700

Vince,

Thanks for your help. In my situation this all works
well except for situations where my file names contain
blank spaces. When I strip down the filenames of their
spaces, the rename works well. How can I rename the
files but keep the spaces?
I have reviewed the "for" command in Windows help, but
it's too complicated for me to understand. I'm guessing
that the FOR /f parameter parses the original file name
into the variable "f", stripping the name of it's
spaces. What actually happens is that, not only does it
strip the filename of it's spaces, it trunkates the file
name at the position the space occurs. In doing so,
rename command can't find the file name to rename when it
compares the original filename with the name in the
variable.

I have some programming skills and experience in MS
Foxpro so I have a feel for some of this thing, but I'm
lost when it comes to the Windows or DOS commands and
their parameters.

Jerry

>-----Original Message-----
>Here's a one-liner that seems to work here in a folder
with 1000 files
>(no guarantees).
>
> for /f %f in ('dir /b') do ren "%f" "c_%f"
>
>That is: for each line in the output of the 'DIR /B"
command (bare file
>names), rename the file with the prefix "c_". I used
double quotes to
>avoid problems with file names containing spaces.
>
>Try 'FOR /?' for more info on the FOR command
>
>Using wildcards generally won't work. Wildcards cause
windows to
>enumerate the files in a directory. Using a command
like the one below,
>it is easy to get CMD.EXE into a loop wherein it keeps
finding new files
>(the newly renamed ones) and renames them again.
>
> Don't do this: for %f in (*.*)
do ren %f c_%f
>
>
>On Fri, 3 Sep 2004 20:24:19 -0700, "Jerry Blake"
><bbibooks@hawaii.rr.com> wrote:
>
>>I have a folder with many files in it that I want to
>>rename with a common prefix. I want to add "c_" to
the
>>front end of a filename and I want to do that all in
one
>>fell swoop like this from a run cmd line:
>>
>>Ren *.* c_*.*
>>
>>It substitutes c_ for the first 2 characters of the
>>existing filename.
>>
>>I've also tried ren *.* c_ & *.* and ren *.* + *.*
and
>>they don't work. If this can be done from other than
the
>>command line, that would be acceptable, as long as I
>>don't have to rename each file individually.
>>Any ideas?
>>
>>Jerry
>
>--
> - Vince
>.
>



Relevant Pages

  • Re: Cant Rename a File Using WinXP Command Prompt!!!
    ... It needs to be given a shorter name so that it can be ... I cannot rename it using the Command Prompt and the ... The old filename in question contains the following symbols as ...
    (microsoft.public.windowsxp.help_and_support)
  • Cant Rename a File Using WinXP Command Prompt!!!
    ... It needs to be given a shorter name so that it can be ... I've used the DIR command to list the files in this sub-directory. ... The old filename in question contains the following symbols as part ... The type of file I'm trying to rename is an askSam file>> *.ask ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Cant Rename a File Using WinXP Command Prompt!!!
    ... It needs to be given a shorter name so that it can be ... I've used the DIR command to list the files in this sub-directory. ... The old filename in question contains the following symbols as part ... The type of file I'm trying to rename is an askSam file>> *.ask ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Renaming multiple files
    ... PcCare used advanced batch file techniques in his reply. ... This command enumerates all .jpg files in the current ... folder and invokes the "rename" subroutine, ... This command sets the variable "filename" to the value ...
    (microsoft.public.windowsxp.general)
  • Re: Changing Uppercase filenames into Lowercase
    ... uppercase filename to a lowercase filename, ... foundfile = f$searchcommand line. ... Based on a command procedure by Willem Grooters which was ...
    (comp.os.vms)