Jump to content

Need help with weird command prompt problem


Recommended Posts

Posted

ok, so i've got a bunch of sequential files in a directory that i'm trying to rename all at once thru the commant prompt, but i'm having a problem (and yes, i made sure i'm in the correct directory first....)

the file names are: 164__00.jpg thru 164__50.jpg

and i want to rename them to: 164_00.jpg thru 164_50.jpg

so in the command prompt i type:

ren 164__**.* 164_**.*

but it does absolutely nothing?!

also, i have some files named: __hr_Page_00.jpg thru __hr_Page_50.jpg

and i want to rename them to: 181_00.jpg thru 181_50.jpg

so in the command prompt i type:

ren __hr_Page_**.* 181_**.*

but i end up with files named: 181__Page_00.jpg thru 181__Page_50.jpg

anyone have a clue why this isn't working? i'm on WinXP Pro SP2, if it makes a difference....and using cmd.exe, not command.com, as it's much easier to work with long filename support.


Posted

I would say it has to do with the wildcard matching. Try using a variable for your number value of the file name and create a loop for the renaming.

Posted
I would say it has to do with the wildcard matching.  Try using a variable for your number value of the file name and create a loop for the renaming.

i don't quite follow you.......example?

Posted (edited)

for %i in (00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50) do ren 164__%i.jpg 164_%i.jpg

Not the most efficient method, but this will work.

Edited by jcarle
Posted (edited)

I am not a script writer, but I came up with this script, It only limitation so far is the amount loops I have it set at = 5.

It is set for text files in this script, but change the extention name to suit your needs

Test this from this location

F:\Documents and Settings\Gunsmokingman\Desktop

Looking For This Location

C:\Temp1

Red Is The File It Looking For With Wild Card

Blue Are Some Varibles For Location File Name

Purple Is A Counter That I Added To Count The loops And Quit

Green Is The New Name Change to Suit Your needs

EG (FPath & "\EG 181_50.jpg")

Orange The Number Of Files If You Have 50 files

then set the Number to 50

Change this Fso.CopyFile to Fso.MoveFile if you only want one file

left if it left as copy it will leave the original plus new name in the folder.

Re Edit Code

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")

Dim INTA : INTA = 1-1

strComputer = "."

  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

  Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile Where FileName Like '164%'")

For Each objFiles in colFiles

INTA = INTA+ 1

FPath = UCase(objFiles.Drive & objFiles.Path)

  CreateObject("Wscript.Shell").popup ObjFiles.Name,3,Date(), 0 + 32

  Fso.CopyFile(ObjFiles.Name),(FPath & "\Test" & INTA & ".Txt" )

  If INTA = 5 Then

  Set objWMIService = Nothing

  Set colFiles = Nothing

  Exit For

  End If

Next

Edited by gunsmokingman
Posted
for %i in (00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50) do ren 164__%i.jpg 164_%i.jpg

Not the most efficient method, but this will work.

Yes, this could be refined to:

for /L %i in (1,1,50) do ren 164__%i.jpg 164_%i.jpg

Posted

thanks for the responses guys......i did a little searching, and came up with an awesome, user-friendly solution. it's called Better File Rename. it's an explorer extension that has TONS of features, and is really easy to use.

if anyone is interested, check it out at: Better File Rename for Windows

Posted

a.)

for /f "usebackq delims=_. tokens=1-3" %%i IN (`dir /b 164*.jpg`) DO ren %%i__%%j.%%k %%i_%%j.%%k

b.)

for /f "usebackq delims=_. tokens=1-3" %%i IN (`dir /b __hr*.jpg`) DO ren __hr_page_%%k.jpg 180_%%k.jpg

Posted

Try using the "?" wildcard instead... If I remember correctly, "?" denotes just "1" character, rather than "1 or more" as the "*" wildcard implies.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...