Remove last 4 characters using VB script from folder name [duplicate]












-2
















This question already has an answer here:




  • How Do I Use VBScript to Strip the First n Characters of a String?

    4 answers




I am new to VB script and trying to create a script in which i am looping in a folder and printing all the subfolder names in a output text file.



All the subfolders have same 4 characters at the -tst , i want to remove this last 4 character and print rest of the name.



For example - original name - Test_name-tst
expected output name - Test_name .



    'Creates new log file and write in it
Set FSO = CreateObject("Scripting.FileSystemObject")
outFile="D:Testtest_output.LOG"
Set objFile = FSO.CreateTextFile(outFile,True)

objFile.Write "START_" & vbCrLf
strFolder ="C:appsTest"
'Get a reference to the folder you want to search
Set FLD = FSO.GetFolder(strFolder).Subfolders
'Loop through the folder and get the file names
For Each Fil In FLD
If InStr(Fil.Name , "-prj") Then
objFile.Write Fil.Name & vbCrLf
End If
Next


Thank you.










share|improve this question













marked as duplicate by Lankymart, Geert Bellekens, Matthieu Brucher, TylerH, Pearly Spencer Nov 26 '18 at 20:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1





    Take a look at the Left() and Len() functions

    – Arno van Boven
    Nov 23 '18 at 16:03











  • This is barely a question, as @ArnovanBoven has already said Left(Fil.Name, Len(Fil.Name) - 4).

    – Lankymart
    Nov 23 '18 at 19:33
















-2
















This question already has an answer here:




  • How Do I Use VBScript to Strip the First n Characters of a String?

    4 answers




I am new to VB script and trying to create a script in which i am looping in a folder and printing all the subfolder names in a output text file.



All the subfolders have same 4 characters at the -tst , i want to remove this last 4 character and print rest of the name.



For example - original name - Test_name-tst
expected output name - Test_name .



    'Creates new log file and write in it
Set FSO = CreateObject("Scripting.FileSystemObject")
outFile="D:Testtest_output.LOG"
Set objFile = FSO.CreateTextFile(outFile,True)

objFile.Write "START_" & vbCrLf
strFolder ="C:appsTest"
'Get a reference to the folder you want to search
Set FLD = FSO.GetFolder(strFolder).Subfolders
'Loop through the folder and get the file names
For Each Fil In FLD
If InStr(Fil.Name , "-prj") Then
objFile.Write Fil.Name & vbCrLf
End If
Next


Thank you.










share|improve this question













marked as duplicate by Lankymart, Geert Bellekens, Matthieu Brucher, TylerH, Pearly Spencer Nov 26 '18 at 20:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1





    Take a look at the Left() and Len() functions

    – Arno van Boven
    Nov 23 '18 at 16:03











  • This is barely a question, as @ArnovanBoven has already said Left(Fil.Name, Len(Fil.Name) - 4).

    – Lankymart
    Nov 23 '18 at 19:33














-2












-2








-2









This question already has an answer here:




  • How Do I Use VBScript to Strip the First n Characters of a String?

    4 answers




I am new to VB script and trying to create a script in which i am looping in a folder and printing all the subfolder names in a output text file.



All the subfolders have same 4 characters at the -tst , i want to remove this last 4 character and print rest of the name.



For example - original name - Test_name-tst
expected output name - Test_name .



    'Creates new log file and write in it
Set FSO = CreateObject("Scripting.FileSystemObject")
outFile="D:Testtest_output.LOG"
Set objFile = FSO.CreateTextFile(outFile,True)

objFile.Write "START_" & vbCrLf
strFolder ="C:appsTest"
'Get a reference to the folder you want to search
Set FLD = FSO.GetFolder(strFolder).Subfolders
'Loop through the folder and get the file names
For Each Fil In FLD
If InStr(Fil.Name , "-prj") Then
objFile.Write Fil.Name & vbCrLf
End If
Next


Thank you.










share|improve this question















This question already has an answer here:




  • How Do I Use VBScript to Strip the First n Characters of a String?

    4 answers




I am new to VB script and trying to create a script in which i am looping in a folder and printing all the subfolder names in a output text file.



All the subfolders have same 4 characters at the -tst , i want to remove this last 4 character and print rest of the name.



For example - original name - Test_name-tst
expected output name - Test_name .



    'Creates new log file and write in it
Set FSO = CreateObject("Scripting.FileSystemObject")
outFile="D:Testtest_output.LOG"
Set objFile = FSO.CreateTextFile(outFile,True)

objFile.Write "START_" & vbCrLf
strFolder ="C:appsTest"
'Get a reference to the folder you want to search
Set FLD = FSO.GetFolder(strFolder).Subfolders
'Loop through the folder and get the file names
For Each Fil In FLD
If InStr(Fil.Name , "-prj") Then
objFile.Write Fil.Name & vbCrLf
End If
Next


Thank you.





This question already has an answer here:




  • How Do I Use VBScript to Strip the First n Characters of a String?

    4 answers








vbscript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 15:59









AgranitAgranit

22




22




marked as duplicate by Lankymart, Geert Bellekens, Matthieu Brucher, TylerH, Pearly Spencer Nov 26 '18 at 20:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Lankymart, Geert Bellekens, Matthieu Brucher, TylerH, Pearly Spencer Nov 26 '18 at 20:41


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    Take a look at the Left() and Len() functions

    – Arno van Boven
    Nov 23 '18 at 16:03











  • This is barely a question, as @ArnovanBoven has already said Left(Fil.Name, Len(Fil.Name) - 4).

    – Lankymart
    Nov 23 '18 at 19:33














  • 1





    Take a look at the Left() and Len() functions

    – Arno van Boven
    Nov 23 '18 at 16:03











  • This is barely a question, as @ArnovanBoven has already said Left(Fil.Name, Len(Fil.Name) - 4).

    – Lankymart
    Nov 23 '18 at 19:33








1




1





Take a look at the Left() and Len() functions

– Arno van Boven
Nov 23 '18 at 16:03





Take a look at the Left() and Len() functions

– Arno van Boven
Nov 23 '18 at 16:03













This is barely a question, as @ArnovanBoven has already said Left(Fil.Name, Len(Fil.Name) - 4).

– Lankymart
Nov 23 '18 at 19:33





This is barely a question, as @ArnovanBoven has already said Left(Fil.Name, Len(Fil.Name) - 4).

– Lankymart
Nov 23 '18 at 19:33












2 Answers
2






active

oldest

votes


















0














Thank you all. Left and len worked for me.



var1 = Left(Fil.Name, Len(Fil.Name) - 4)






share|improve this answer































    -2














    Reverse the name, cut the first four characters with Mid() and reverse the string again:



    StrReverse(Mid(StrReverse(Fil.Name), 5))





    share|improve this answer


























    • Not sure reversing a string twice to do what Left() and Len() can do without reversing the string is an efficient approach.

      – Lankymart
      Nov 23 '18 at 19:42


















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Thank you all. Left and len worked for me.



    var1 = Left(Fil.Name, Len(Fil.Name) - 4)






    share|improve this answer




























      0














      Thank you all. Left and len worked for me.



      var1 = Left(Fil.Name, Len(Fil.Name) - 4)






      share|improve this answer


























        0












        0








        0







        Thank you all. Left and len worked for me.



        var1 = Left(Fil.Name, Len(Fil.Name) - 4)






        share|improve this answer













        Thank you all. Left and len worked for me.



        var1 = Left(Fil.Name, Len(Fil.Name) - 4)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 21:48









        AgranitAgranit

        22




        22

























            -2














            Reverse the name, cut the first four characters with Mid() and reverse the string again:



            StrReverse(Mid(StrReverse(Fil.Name), 5))





            share|improve this answer


























            • Not sure reversing a string twice to do what Left() and Len() can do without reversing the string is an efficient approach.

              – Lankymart
              Nov 23 '18 at 19:42
















            -2














            Reverse the name, cut the first four characters with Mid() and reverse the string again:



            StrReverse(Mid(StrReverse(Fil.Name), 5))





            share|improve this answer


























            • Not sure reversing a string twice to do what Left() and Len() can do without reversing the string is an efficient approach.

              – Lankymart
              Nov 23 '18 at 19:42














            -2












            -2








            -2







            Reverse the name, cut the first four characters with Mid() and reverse the string again:



            StrReverse(Mid(StrReverse(Fil.Name), 5))





            share|improve this answer















            Reverse the name, cut the first four characters with Mid() and reverse the string again:



            StrReverse(Mid(StrReverse(Fil.Name), 5))






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 23 '18 at 19:35









            Lankymart

            11.5k438100




            11.5k438100










            answered Nov 23 '18 at 17:00









            jgm27jgm27

            1




            1













            • Not sure reversing a string twice to do what Left() and Len() can do without reversing the string is an efficient approach.

              – Lankymart
              Nov 23 '18 at 19:42



















            • Not sure reversing a string twice to do what Left() and Len() can do without reversing the string is an efficient approach.

              – Lankymart
              Nov 23 '18 at 19:42

















            Not sure reversing a string twice to do what Left() and Len() can do without reversing the string is an efficient approach.

            – Lankymart
            Nov 23 '18 at 19:42





            Not sure reversing a string twice to do what Left() and Len() can do without reversing the string is an efficient approach.

            – Lankymart
            Nov 23 '18 at 19:42



            Popular posts from this blog

            Berounka

            Sphinx de Gizeh

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...