...

View Full Version : Windows Batch File - rename 220 files



snakedoctor
10-03-2007, 09:30 AM
Hi,

I am running Windows Vista Home Premium.

I have a directory that contains 220 files that I want to rename.

The format of some files are as follows:

fileName fileNumber fileSecondaryName (common name).txt

Other files are like:
file Name fileNumber fileSecondaryName (common.name).txt

The only differences are the space in "file name" at the beginning and a period in between the two words in the brackets.

I am after a script that will rename these files by deleting the "fileName or "file name"" and "(common name)" or "(common.name)", including the brackets, from the file name.

That is renamed to:
fileNumber fileSecondaryName.txt

Can anyone help? :)

Regards
Noobie :thumbsup:

Thank you

Dunna
10-04-2007, 04:07 AM
so let me get this straight, you just want your files to say: fileNumber fileSecondaryName.txt ? If so, you can't make a batch do it but I could whip you something up in c++ if you want.

snakedoctor
10-04-2007, 07:27 PM
so let me get this straight, you just want your files to say: fileNumber fileSecondaryName.txt ? If so, you can't make a batch do it but I could whip you something up in c++ if you want.

As long as it will do what I want then yes please.:)

Dunna
10-05-2007, 03:42 AM
ok done, give me an email address to send it to.

and note: if it tells you it failed to rename a bunch of files, it probably isn't true. I messed up the counter code a little but it works fine as long as the files are named 1 of the 2 formats you described. If not, it will simply ignore them.

snakedoctor
10-06-2007, 12:56 PM
ok done, give me an email address to send it to.

and note: if it tells you it failed to rename a bunch of files, it probably isn't true. I messed up the counter code a little but it works fine as long as the files are named 1 of the 2 formats you described. If not, it will simply ignore them.
it's sn4ke.doctor@googlemail.com

ghostdog74
10-06-2007, 02:11 PM
you can't make a batch do it
yes, it can be done, albeit a little tedious

ghostdog74
10-06-2007, 02:12 PM
here's a vbscript



Set objFSO = CreateObject("Scripting.FileSystemObject")
myFolder = "c:\temp" 'Folder where your text files are kept
For Each files In objFSO.GetFolder(myFolder).Files
If InStr(1,files.Name,"(common name)") > 0 Then
strName = Replace(files.Name," (common name)","")
s = Split(strName," ")
strNew = ""
For i = LBound(s) To UBound(s)
If IsNumeric(s(i)) Then
For j = i To UBound(s)
strNew = strNew & " " & s(j)
Next
Exit For
End If
Next
newFileName = Trim(strNew)
files.Name = newFileName
End If
Next

usage : cscript /nologo myscript.vbs

Dunna
10-07-2007, 06:42 PM
that vb script doesn't work for his common.name files. i'm emailing you the program now, tell me if there's a problem. Oh ya, and rename the file from SnakeDoctorsFileRenamer.exe.ERASETHISPART to SnakeDoctorsFileRenamer.exe, because gmail doesn't let you email anything that ends in exe, or a zip that contains one.

ghostdog74
10-08-2007, 02:53 AM
that vb script doesn't work for his common.name files.
Have you tried running it? what doesn't work?

snakedoctor
10-08-2007, 05:30 AM
i'm emailing you the program now, tell me if there's a problem.

Thanks Dunna, That's great. :thumbsup:

Any chance you can part with the source code as I have several directories where I have a similar problem but where the file names are different?

Dunna
11-15-2007, 05:21 PM
Oh, sorry snakedoctor didn't see your post until now. Sure I can give you the source, if you still want it. Just reply here (I'd email right now but I don't have it on me).

snakedoctor
11-16-2007, 08:43 AM
Yes please Dunna.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum