Re: Renaming files using wildcards

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


Date: Sun, 05 Sep 2004 16:15:30 GMT

OK, I forgot that "FOR /F" parses each line into tokens, and your
getting only the first token. So do this:

        for /f "tokens=*" %f in ('dir /b') do ren "%f" "c_%f"

That way, %f will contain all the tokens. That works here with files
whose names contain spaces.

On Sat, 4 Sep 2004 19:22:56 -0700, <anonymous@discussions.microsoft.com>
wrote:

>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
>>.
>>

-- 
 - Vince


Relevant Pages

  • 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: How To Make index.shtml As A Home Page?
    ... is the correct command, but will only be effective if AllowOverride All ... overridden (provided AllowOverride is set) using .htaccess as you have done. ... > DirectoryIndex index.shtml index.html index.htm index.php ... you should be able to open your online web in FrontPage and rename ...
    (microsoft.public.frontpage.client)
  • 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)
  • =?UTF-8?Q?Re:_The_rename_command=E2=80=A6?=
    ... the command would be much more efficient if find was only ... *every* file gets passed to rename. ... the Swedish characters gets "distorted" anyway): ... understanding English in manuals etc). ...
    (Ubuntu)
  • Re: The rename =?windows-1252?Q?command=85?=
    ... From the very beginning of Linux the Windows users had to ... learn that rename is not part of the commands. ... When first starting to use computers, if we do not count the very first ... I accidently found that rename command, ...
    (Ubuntu)