Remove last 4 characters using VB script from folder name [duplicate]
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.
vbscript
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.
add a comment |
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.
vbscript
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 saidLeft(Fil.Name, Len(Fil.Name) - 4)
.
– Lankymart
Nov 23 '18 at 19:33
add a comment |
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.
vbscript
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
vbscript
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 saidLeft(Fil.Name, Len(Fil.Name) - 4)
.
– Lankymart
Nov 23 '18 at 19:33
add a comment |
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 saidLeft(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
add a comment |
2 Answers
2
active
oldest
votes
Thank you all. Left and len worked for me.
var1 = Left(Fil.Name, Len(Fil.Name) - 4)
add a comment |
Reverse the name, cut the first four characters with Mid()
and reverse the string again:
StrReverse(Mid(StrReverse(Fil.Name), 5))
Not sure reversing a string twice to do whatLeft()
andLen()
can do without reversing the string is an efficient approach.
– Lankymart
Nov 23 '18 at 19:42
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thank you all. Left and len worked for me.
var1 = Left(Fil.Name, Len(Fil.Name) - 4)
add a comment |
Thank you all. Left and len worked for me.
var1 = Left(Fil.Name, Len(Fil.Name) - 4)
add a comment |
Thank you all. Left and len worked for me.
var1 = Left(Fil.Name, Len(Fil.Name) - 4)
Thank you all. Left and len worked for me.
var1 = Left(Fil.Name, Len(Fil.Name) - 4)
answered Nov 23 '18 at 21:48
AgranitAgranit
22
22
add a comment |
add a comment |
Reverse the name, cut the first four characters with Mid()
and reverse the string again:
StrReverse(Mid(StrReverse(Fil.Name), 5))
Not sure reversing a string twice to do whatLeft()
andLen()
can do without reversing the string is an efficient approach.
– Lankymart
Nov 23 '18 at 19:42
add a comment |
Reverse the name, cut the first four characters with Mid()
and reverse the string again:
StrReverse(Mid(StrReverse(Fil.Name), 5))
Not sure reversing a string twice to do whatLeft()
andLen()
can do without reversing the string is an efficient approach.
– Lankymart
Nov 23 '18 at 19:42
add a comment |
Reverse the name, cut the first four characters with Mid()
and reverse the string again:
StrReverse(Mid(StrReverse(Fil.Name), 5))
Reverse the name, cut the first four characters with Mid()
and reverse the string again:
StrReverse(Mid(StrReverse(Fil.Name), 5))
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 whatLeft()
andLen()
can do without reversing the string is an efficient approach.
– Lankymart
Nov 23 '18 at 19:42
add a comment |
Not sure reversing a string twice to do whatLeft()
andLen()
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
add a comment |
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