Jump to content

Help me rename these files via batch script


Recommended Posts

I have files that need to be renamed via a batch command.

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

Link to comment
Share on other sites


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

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

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. :unsure:

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 by CharlotteTheHarlot
Link to comment
Share on other sites

Something like this may do it:

@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.

Link to comment
Share on other sites

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. :-)

'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!

Edited by enuffsaid
Link to comment
Share on other sites

Enuff here just place this VBS in the folder where you want

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

Link to comment
Share on other sites

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

  • 1 year later...

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 *.* *.*.edi

But 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 by enuffsaid
Link to comment
Share on other sites

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=%.edi
Does 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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