none
How to do filename manipulations in VB RRS feed

  • Question

  • 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 is 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 is 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 is 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 is 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"
    date_text = Date
    rplacedate = Format(date_text, "yyyymmdd")
    Set objfolder = ObjFSO.getfolder(objStartFolder)
    Set colfiles = objfolder.Files
    For Each objFile In colfiles
    MsgBox objFile.Name
    temparr1 = Split(objFile.Name, "_")
    MsgBox temparr1(1)
     If temparr1(1) = "555A" Or "555a" And temparr1(2) = "ORANGE" or temparr1(2)="Orange" Then
        objFile.Name = "BB_Orange_555a+_rplacedate.txt"
      End If
      Next


    • Edited by Shan455 Wednesday, May 8, 2019 8:44 AM
    • Moved by KareninstructorMVP Wednesday, May 8, 2019 9:11 AM Moved from vb.net forum
    Wednesday, May 8, 2019 8:43 AM

All replies

  • Hi,

    According to your description, your issue is more related about VBS. And this forum is discussing and asking questions about the vb.net.

    Ask in the following forum.

    https://social.technet.microsoft.com/Forums/scriptcenter/en-us/home?forum=ITCG

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 8, 2019 8:47 AM