Help me rename these files via batch script
#1
Posted 10 January 2013 - 08:55 AM
The file name is like:
TSP1PayStatus010512
The 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
#3
Posted 10 January 2013 - 09:40 AM
Cheers and Regards
#4
Posted 10 January 2013 - 11:39 AM
enuffsaid, on 10 January 2013 - 08:55 AM, said:
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
#5
Posted 10 January 2013 - 11:46 AM
WScript.Echo Replace("TSP1PayStatus010512","TSP1","TSP")
Results TSPPayStatus010512
#6
Posted 10 January 2013 - 11:59 AM
I'm pretty sure this is a revisit of an older topic with a functional example.
#7
Posted 10 January 2013 - 12:11 PM
submix8c, on 10 January 2013 - 11:59 AM, said:
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 ).
This post has been edited by CharlotteTheHarlot: 10 January 2013 - 12:12 PM
#8
Posted 10 January 2013 - 01:09 PM
@ECHO OFF SETLOCAL ENABLEEXTENSIONS PUSHD X:\MYDIR\SUBDIR FOR %%# IN (TSP1PayStatus*.*) DO CALL :RF %%# POPD ENDLOCAL GOTO :EOF :RF SET "_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.
#9
Posted 11 January 2013 - 02:47 AM
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. :-)
'nuff
EDIT: 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!
This post has been edited by enuffsaid: 11 January 2013 - 03:17 AM
#10
Posted 11 January 2013 - 05:03 PM
to rename them. If you need a script that will loop threw all
folders and sub fulder to look for the file post a request.
Rename any file with TSP1 as it first 4 digets
Dim 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
#11
Posted 14 January 2013 - 02:50 AM
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
- ← Copy file to all users
- Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
- Batch file for searching for file duplicates →



Help

Back to top









