Re: File Rename Utility

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Rob Stow (rob.stow_at_sasktel.net)
Date: 10/19/04


Date: Tue, 19 Oct 2004 10:14:01 -0600

Dragon wrote:
> Thank you. It seems to work great except that I found a couple of anomalies.
>
> My commands were:
>
> for /F "tokens=*" %%* in ('dir /b *051*.*') do ren "%%*" "%%* ABC.XYZ
> for /F "tokens=*" %%* in ('dir /b *052*.*') do ren "%%*" "%%* DEF.XYZ
> for /F "tokens=*" %%* in ('dir /b *053*.*') do ren "%%*" "%%* GHI.XYZ
> ... Up to *114*...
>
> For some reason it picked up file names with 001,011,014 etc that were not
> part of the criteria. Any ideas?
>

I know exactly why that is happening and it is
not your fault - MicroSoft f*cked up in a big way.

Something like "dir *token*.*" not only picks up
all files containing "token" in the filename, but
also all files containing "token" in the 8.3 filename.

Take a look at the results of "dir /x", which will
display both the long and 8.3 names of the files.

Normally the 8.3 filenames don't cause a problem
because they are usually just a truncated version
of the long file name, but sometimes there are
incongruities between the 8.3 and long names.

For that reason, you should *never* trust the output
of expressions that use wildcards (* or ?). You can
use the wildcarded expression to generate a list of
files or folders to process, but you still need to
inspect each file/folder on that list before doing
anything with it.

I suggest you try modifying your batch file so that
it checks for a tilde in the filename. If no tilde,
then procede with the rename, else do nothing.

> Thank you.
>
>
> "Pegasus (MVP)" <I.can@fly.com> wrote in message
> news:%23AwujKXtEHA.2800@TK2MSFTNGP10.phx.gbl...
>
>>"Dragon" <NoSpam_Baadil@hotmail.com> wrote in message
>>news:u3fpM9UtEHA.1308@tk2msftngp13.phx.gbl...
>>
>>>Does anyone know of a utility that allows you to get renaming criteria
>>
>>from
>>
>>>a file and then rename the files in a particular folder. for Example:
>>>
>>>Files Names (Current)
>>>
>>>P001A_asdsd.xyz
>>>Q001B_fdsdffdd.xyz
>>>R001_dsdsdsds.xyz
>>>P002A_asasa.xyz
>>>P002B_hghghgh.xyz
>>>Q003_rerere.xyz
>>>
>>>Criteria in the File:
>>> Look for: *002* Rename to BBBBBBBB_%fileName%
>>> Look for: *003* Rename to CCCCCCCC_%fileName%
>>>
>>>Result
>>>
>>>P001A_asdsd.xyz
>>>Q001B_fdsdffdd.xyz
>>>R001_dsdsdsds.xyz
>>>BBBBBBBB_P002A_asasa.xyz
>>>BBBBBBBB_P002B_hghghgh.xyz
>>>CCCCCCCC_Q003_rerere.xyz
>>>
>>>Thank you.
>>>
>>>
>>
>>Try this:
>>
>>@echo off
>>for /F "tokens=*" %%* in ('dir /b *002*.*') do echo ren "%%*"
>>"BBBBBBBB%%*"
>>for /F "tokens=*" %%* in ('dir /b *003*.*') do echo ren "%%*"
>>"CCCCCCCC%%*"
>>
>>Remove "echo" when you're satisfied that it does what you want it to do.
>>
>>
>
>
>



Relevant Pages

  • Re: LPCWSTR Variable Corrupted
    ... FileName is an optional parameter "int OpenFile(LPCTSTR FileName = ... Open(pszFileName, openFlags, NULL)) ... The reason I suggested const CString & is to break the OP of the habit of creating a lot ...
    (microsoft.public.vc.mfc)
  • Re: Tilde expansion on (Windows)files?
    ... working on a storage optimization system I realized, ... What does this mean, which filename is searched? ... If it works on Windows, why doesn't it find the file? ... E.g. the tilde expansion only makes sense in a user specific environment ...
    (comp.lang.tcl)
  • IFS tilde in filename
    ... The filename is generated by the application ... only thing we need to do is remove the tilde character ... When I try to rename the file with legacy commands, the ... The one option we have is to manually go to the IFS filder via the ...
    (comp.sys.ibm.as400.misc)
  • Re: Tilde expansion on (Windows)files?
    ... Tcl 8.5.4, Windows XP - test: ... What does this mean, which filename is searched? ... If it works on Windows, why doesn't it find the file? ... 'file normalize' interaction with tilde ...
    (comp.lang.tcl)
  • Re: HANDLE hFile
    ... and that fileName is not a variable name; if it is a variable name, ... since it only makes sense when string or character literals are used. ... There is always a reason, and you didn't give the reason. ... It works on debug mode. ...
    (microsoft.public.vc.mfc)