Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Windows Batch File - rename 220 files

    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

    Thank you

  • #2
    Regular Coder
    Join Date
    May 2004
    Location
    New Hampshire, America
    Posts
    246
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dunna View Post
    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.

  • #4
    Regular Coder
    Join Date
    May 2004
    Location
    New Hampshire, America
    Posts
    246
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dunna View Post
    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

  • #6
    New Coder
    Join Date
    May 2006
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Dunna View Post
    you can't make a batch do it
    yes, it can be done, albeit a little tedious

  • #7
    New Coder
    Join Date
    May 2006
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post
    here's a vbscript

    Code:
    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

  • #8
    Regular Coder
    Join Date
    May 2004
    Location
    New Hampshire, America
    Posts
    246
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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.
    Last edited by Dunna; 10-07-2007 at 06:46 PM.

  • #9
    New Coder
    Join Date
    May 2006
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Dunna View Post
    that vb script doesn't work for his common.name files.
    Have you tried running it? what doesn't work?

  • #10
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dunna View Post
    i'm emailing you the program now, tell me if there's a problem.
    Thanks Dunna, That's great.

    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?

  • #11
    Regular Coder
    Join Date
    May 2004
    Location
    New Hampshire, America
    Posts
    246
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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).
    Last edited by Dunna; 11-15-2007 at 05:27 PM.

  • #12
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes please Dunna.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •