Re: Renaming files using wildcards

From: Vincent Fatica (abuse_at_localhost.com)
Date: 09/04/04


Date: Sat, 04 Sep 2004 04:40:33 GMT

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: Renaming files using wildcards
    ... When I strip down the filenames of their ... spaces, the rename works well. ... strip the filename of it's spaces, ... rename command can't find the file name to rename when it ...
    (microsoft.public.windowsxp.general)
  • 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: Great SWT Program
    ... a good tutorial on Unix CLI tools? ... command there, ... then rename everything in the search scope with the CLI, ... I'd have to boot up a Windows system and try stuff, ...
    (comp.lang.java.programmer)
  • 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)