MSFN Forum: Help me rename these files via batch script - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Help me rename these files via batch script Rate Topic: -----

#1 User is offline   enuffsaid 

  • Friend of MSFN
  • PipPipPipPipPip
  • Group: Members
  • Posts: 865
  • Joined: 26-December 03

Posted 10 January 2013 - 08:55 AM

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


#2 User is offline   Tripredacus 

  • K-Mart-ian Legend
  • Group: Super Moderator
  • Posts: 8,689
  • Joined: 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Posted 10 January 2013 - 09:17 AM

What have you tried so far?

#3 User is offline   bphlpt 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,082
  • Joined: 12-May 07

Posted 10 January 2013 - 09:40 AM

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

#4 User is offline   CharlotteTheHarlot 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,172
  • Joined: 24-September 07
  • OS:none specified
  • Country: Country Flag

Posted 10 January 2013 - 11:39 AM

View Postenuffsaid, on 10 January 2013 - 08:55 AM, said:

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

#5 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 10 January 2013 - 11:46 AM

Here a simple VBS solution
WScript.Echo Replace("TSP1PayStatus010512","TSP1","TSP")

Results TSPPayStatus010512

#6 User is offline   submix8c 

  • Inconceivable!
  • Group: Patrons
  • Posts: 3,247
  • Joined: 14-September 05
  • OS:none specified
  • Country: Country Flag

Posted 10 January 2013 - 11:59 AM

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:

#7 User is offline   CharlotteTheHarlot 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,172
  • Joined: 24-September 07
  • OS:none specified
  • Country: Country Flag

Posted 10 January 2013 - 12:11 PM

View Postsubmix8c, on 10 January 2013 - 11:59 AM, said:

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

This post has been edited by CharlotteTheHarlot: 10 January 2013 - 12:12 PM


#8 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,364
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 10 January 2013 - 01:09 PM

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 User is offline   enuffsaid 

  • Friend of MSFN
  • PipPipPipPipPip
  • Group: Members
  • Posts: 865
  • Joined: 26-December 03

Posted 11 January 2013 - 02:47 AM

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!

This post has been edited by enuffsaid: 11 January 2013 - 03:17 AM


#10 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 11 January 2013 - 05:03 PM

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



#11 User is offline   enuffsaid 

  • Friend of MSFN
  • PipPipPipPipPip
  • Group: Members
  • Posts: 865
  • Joined: 26-December 03

Posted 14 January 2013 - 02:50 AM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy