Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

Help me rename these files via batch script

- - - - -

  • Please log in to reply
12 replies to this topic

#1
enuffsaid

enuffsaid

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 866 posts
  • Joined 26-December 03
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


How to remove advertisement from MSFN

#2
Tripredacus

Tripredacus

    K-Mart-ian Legend

  • Super Moderator
  • 9,814 posts
  • Joined 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Donator

What have you tried so far?
MSFN RULES | GimageX HTA for PE 3-5 | lol probloms
msfn2_zpsc37c7153.jpg

#3
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,798 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag
That should be able to be done via batch, but you might also try the free bulk rename utility - http://www.bulkrenam.../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

Posted Image


#4
CharlotteTheHarlot

CharlotteTheHarlot

    MSFN Master

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,054 posts
  • Joined 24-September 07
  • OS:none specified
  • Country: Country Flag

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

... Let him who hath understanding reckon the Number Of The Beast ...


#5
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
Here a simple VBS solution
WScript.Echo Replace("TSP1PayStatus010512","TSP1","TSP")
Results TSPPayStatus010512


GunSmokingMan



#6
submix8c

submix8c

    Inconceivable!

  • Patrons
  • 4,282 posts
  • Joined 14-September 05
  • OS:none specified
  • Country: Country Flag
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:

Someday the tyrants will be unthroned... Jason "Jay" Chasteen; RIP, bro!

Posted Image


#7
CharlotteTheHarlot

CharlotteTheHarlot

    MSFN Master

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,054 posts
  • Joined 24-September 07
  • OS:none specified
  • Country: Country Flag

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, 10 January 2013 - 12:12 PM.

... Let him who hath understanding reckon the Number Of The Beast ...


#8
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,534 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.

#9
enuffsaid

enuffsaid

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 866 posts
  • Joined 26-December 03
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, 11 January 2013 - 03:17 AM.


#10
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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



GunSmokingMan



#11
enuffsaid

enuffsaid

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 866 posts
  • Joined 26-December 03
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

#12
enuffsaid

enuffsaid

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 866 posts
  • Joined 26-December 03

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, 25 March 2014 - 08:59 AM.


#13
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,534 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Untested example based upon the last solution I gave:
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
PUSHD X:\MYDIR\SUBDIR
FOR /F "TOKENS=*" %%# IN ('DIR/B/A-D TSP1PayStatus*.*') DO (IF %%~z# NEQ 0 CALL :RF %%#)
POPD
ENDLOCAL
GOTO :EOF

:RF
SET "_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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN