enuffsaid Posted January 10, 2013 Share Posted January 10, 2013 I have files that need to be renamed via a batch command.The file name is like:TSP1PayStatus010512The constants are "TSP1PayStatus" followed by the date. I need the "1" between "TSP" and "PayStatus" removed via a batch script so...TSP1PayStatus010512 should become TSPPayStatus010512.Any suggestions? Thanks very much.'nuff Link to comment Share on other sites More sharing options...
Tripredacus Posted January 10, 2013 Share Posted January 10, 2013 What have you tried so far? Link to comment Share on other sites More sharing options...
bphlpt Posted January 10, 2013 Share Posted January 10, 2013 That should be able to be done via batch, but you might also try the free bulk rename utility - http://www.bulkrenameutility.co.uk/Main_Intro.php. One of its options is to remove a fixed number of characters from a fixed position in a file name so that fits your current situation. It also has many, many other options.Cheers and Regards Link to comment Share on other sites More sharing options...
CharlotteTheHarlot Posted January 10, 2013 Share Posted January 10, 2013 TSP1PayStatus010512 should become TSPPayStatus010512.Assuming that period at the end of that quoted sentence is not what you want ...ren "TSP1PayStatus010512" "TSPPayStatus010512"That batch file would need to be in the same exact folder as the file. It would be better if you mentioned the exact path to the file so it could be included in the script because then the batch file could be located anywhere.Why don't you just select that file, Press the F2 key, and then paste this name directly on it ... TSPPayStatus010512 Link to comment Share on other sites More sharing options...
gunsmokingman Posted January 10, 2013 Share Posted January 10, 2013 Here a simple VBS solutionWScript.Echo Replace("TSP1PayStatus010512","TSP1","TSP")Results TSPPayStatus010512 Link to comment Share on other sites More sharing options...
submix8c Posted January 10, 2013 Share Posted January 10, 2013 I believe the OP wishes to Mass-Rename "TSP1" filenames to "TSP" filenames.I'm pretty sure this is a revisit of an older topic with a functional example. Link to comment Share on other sites More sharing options...
CharlotteTheHarlot Posted January 10, 2013 Share Posted January 10, 2013 (edited) I believe the OP wishes to Mass-Rename "TSP1" filenames to "TSP" filenames.I'm pretty sure this is a revisit of an older topic with a functional example. Ah, I see you're correct after re-reading. Not enough info given IMHO though. Quantity of files?I would still personally do this in a batch script given a list of the files just to be accurate and make no mistakes.Multiple renamers are great, but you usually first have to teach the person how to understand Expressions.I like the one called Scarabée Siren which has insane string handling flexibility. ( Insanely good ). Edited January 10, 2013 by CharlotteTheHarlot Link to comment Share on other sites More sharing options...
Yzöwl Posted January 10, 2013 Share Posted January 10, 2013 Something like this may do it:@ECHO OFFSETLOCAL ENABLEEXTENSIONSPUSHD X:\MYDIR\SUBDIRFOR %%# IN (TSP1PayStatus*.*) DO CALL :RF %%#POPDENDLOCALGOTO :EOF:RFSET "_FN=%*"REN %_FN% TSP%_FN:*1=%If the script is being run from the directory containing the files you should be okay to remove lines 3 & 5; If not replace the path on line 3 with yours. Link to comment Share on other sites More sharing options...
enuffsaid Posted January 11, 2013 Author Share Posted January 11, 2013 (edited) Hi Everybody,Yes, I want to mass rename batch files. The batch will be scheduled to run daily. I know that the files are named TSP1PayStatusddmmyy where ddmmyy is the date. Eg. TSP1PayStatus010512.Usually there is only 1 new file per day, sometimes 2. A software application generates the file but they then need to be renamed on a daily basis so the system can process them correctly, after which they will be automatically removed / deleted. The developers won't correct the application so I need to rename these files manually on a daily basis. It's a quick job but surely this can be automated?I've googled and tried various scripts but none have worked so for. My batch script knowledge is very limited and the scripts I've tried so far are mostly just simple "ren" commands.I'm really looking for a simple batch file and not a utility like "BulkRename" as still will be running on a server and server team can be a bit picky about what's allowed to run on the server.I will give gunsmokingman's VBS script a try because it's nice and small. If not I'll give Yzöwl's batch script an attempt.Thank you all very much for your input, folks. I will test it and allow it to run for a few days and then report back the results.Cheers everybody. Have a good weekend in advance. :-)'nuffEDIT: Just noticed the VBS script looks for a filename with the specific date in it. I can't replace that date with variables / wildcard characters, can I. For now it seems the batch example provided by Yzöwl works miracles. Thanks! Edited January 11, 2013 by enuffsaid Link to comment Share on other sites More sharing options...
gunsmokingman Posted January 11, 2013 Share Posted January 11, 2013 Enuff here just place this VBS in the folder where you wantto rename them. If you need a script that will loop threw allfolders and sub fulder to look for the file post a request.Rename any file with TSP1 as it first 4 digetsDim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")Dim i For Each i In Fso.GetFolder(".").Files If InStr(1,i.Name,"TSP1",1) And Left(LCase(i.Name),4)="tsp1" Then Fso.MoveFile i.Path, Replace(i.Path,Left(i.Name,4),"TSP") End If Next Link to comment Share on other sites More sharing options...
enuffsaid Posted January 14, 2013 Author Share Posted January 14, 2013 Thank you Gunsmoking man. :-)For now I'm using Yzöwl's script as batch files are slightly less abracadabra to me than VBS is.So far the Batch script seems to work perfectly fine for us. But I have archived your VBS script, nevertheless.Thanks very much.'nuff Link to comment Share on other sites More sharing options...
enuffsaid Posted March 25, 2014 Author Share Posted March 25, 2014 (edited) Dear scripters.Could I pick your brain once more...We have an FTP site where EDIs are pulled in. They then need to be renamed to get the *.EDI extension:ren *.* *.*.ediBut amongst those files on the FTP site there are a lot of files with 0 byte size. We'd like for those NOT to be renamed. Or... another way of putting it, rename all files that are larger than 0 bytes.It would also be okay if we move the zero byte files to another folder and then rename whichever files are left.Is there some simple code for this you can assist me with?I salute you.'nuff Edited March 25, 2014 by enuffsaid Link to comment Share on other sites More sharing options...
Yzöwl Posted March 25, 2014 Share Posted March 25, 2014 Untested example based upon the last solution I gave:@ECHO OFFSETLOCAL ENABLEEXTENSIONSPUSHD X:\MYDIR\SUBDIRFOR /F "TOKENS=*" %%# IN ('DIR/B/A-D TSP1PayStatus*.*') DO (IF %%~z# NEQ 0 CALL :RF %%#)POPDENDLOCALGOTO :EOF:RFSET "_FN=%*"REN %_FN% TSP%_FN:*1=%.ediDoes the same thing as the original except that it appends the .edi extension and ignores all files of zero bytes. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now