Computing.Net > Forums > Programming > rename using parts of file name

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

rename using parts of file name

Reply to Message Icon

Name: premam
Date: August 22, 2008 at 01:52:07 Pacific
OS: windows 2000
CPU/Ram: 2.40GHz/2Gb
Comment:

I would like to rename all files in \\gbrcrotpc8ms008\rss_data_transfer_gb77$\interface\planning_Reports in the following way:

INVRPT_5023949000004_20080721061325.GB to 5023949000004_MSG_IN_20080721061325.GB

PPRHDR_5017416000006_20080721061424_00000980.GB_m to 5017416000006_MSG_IN_20080721061424_00000980.GB_m

SLSRPT_5023949000004_20080721061317_00000978.GB to 5023949000004_MSG_IN_20080721061317_00000978.GB

Basically I would like to drop first 7 characters from file name. Then insert MSG_IN_ after next 14 characters and leave rest of file name as it is.

I would like to do this using batch script file.

I have not used scripts before and would appreciate help to achieve this.



Sponsored Link
Ads by Google

Response Number 1
Name: premam
Date: August 22, 2008 at 02:16:10 Pacific
Reply:

I would like to add that number of files and the names in the directory will vary from week to week but same renaming rules will be applied to all of them.


0

Response Number 2
Name: ghostdog
Date: August 22, 2008 at 17:51:50 Pacific
Reply:

vbscript


Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\test"
Set objFolder = objFSO.GetFolder(strFolder)
For Each strFiles In objFolder.Files
If objFSO.GetExtensionName(strFiles) = "GB" Then
strComponents = Split(strFiles.Name,"_")
strComponents(0)=strComponents(1)
strComponents(1)="MSG_IN"
strFiles.Name = Join(strComponents,"_")
End If
Next

save the above as script.vbs and on command line:


c:\test> cscript /nologo script.vbs


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: rename using parts of file name

batch rename files with a part of.. www.computing.net/answers/programming/batch-rename-files-with-a-part-of/16747.html

Renaming a directory of files with spaces www.computing.net/answers/programming/renaming-a-directory-of-files-with-spaces/19875.html

rename multiple file whit batch fil www.computing.net/answers/programming/rename-multiple-file-whit-batch-fil/9028.html