Asked by:
How to do filename manipulations in VB

General discussion
-
I am completely newbie to VB Scripting. Can someone help me with a requirement where I have list of files in a directory, I want to manipulate the filenames in required format as mentioned below.
< Filenames present in directory > AAAL_555A_ORANGE_F190404_D190408.TXT.freshfruits_20190422-115617 AAAL_555A_MANGO_F190404_D190408.TXT.freshfruits_20190422-120939 AAAL_555B_APPLE_F190404_D190408.TXT.freshfruits_20190422-121449 AAAL_555B_ORANGE_F190404_D190408.TXT.freshfruits_20190422-115617 AAAL_555B_Orange_F190404_D190408.TXT.freshfruits_20180422-115617 <After modification > If 2nd string 555A and 3rd string is ORANGE or 2nd string 555A and 3rd string is Orange the filename should be BB_Orange_555a_date +'%Y%m%d'.txt If 2nd string 555B and 3rd string is ORANGE or 2nd string 555A and 3rd string is Orange the filename should be BB_Orange_555b_date +'%Y%m%d'.txt If 2nd string 555B and 3rd string is APPLE or 2nd string 555A and 3rd string is Apple the filename should be BB_Apple_555b_date +'%Y%m%d'.txt If 2nd string 555A and 3rd string is MANGO or 2nd string 555A and 3rd string is Mango the filename should be BB_Mango_555a_date +'%Y%m%d'.txt
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\test"
Set objfolder = ObjFSO.getfolder(objStartFolder)
Set colfiles = objfolder.Files
For Each objFile In colfiles
'MsgBox objFile.Name
temparr1 = Split(objFile.Name, "_")
'MsgBox temparr1(1)next
- Changed type Bill_Stewart Thursday, September 5, 2019 9:24 PM
- Moved by Bill_Stewart Thursday, September 5, 2019 9:24 PM This is not "design solution for me" forum
Wednesday, May 8, 2019 8:51 AM
All replies
-
You should not be using VBScript as it is obsolete. We use PowerShell now.
To change a file name you will need to use the rename method CmdLet in PowerShell. To change the file name you would use the "-replace" operator.
Microsoft Virtual Academy - Getting Started with Microsoft PowerShell
\_(ツ)_/
Wednesday, May 8, 2019 9:06 AM -
Thanks for your suggestion , But my requirement is in VB scripting .Kindly help.. :)Wednesday, May 8, 2019 11:57 AM
-
Download the VBscript help files so that you have a reference.
http://download.microsoft.com/download/winscript56/Install/5.6/W982KMeXP/EN-US/scrdoc56en.exe
Here is sample to rename a file. https://stackoverflow.com/questions/17660117/rename-a-file-using-vbscript
Wednesday, May 8, 2019 12:48 PM -
But my requirement is in VB scripting .
Why?
Kindly help.. :)
Please read this first:
This forum is for scripting questions rather than script requests
-- Bill Stewart [Bill_Stewart]
Wednesday, May 8, 2019 2:08 PM