Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 688

Replace Character(s) in filenames. e.g. He&llo => Hello in Visual Studio

$
0
0
Hi,

I have a Code made in Visual studio 2010 that is kinda working.

If a file has a character that i want to remove i browse to the folder and from there i can replace the Filename.
if the code runs, he replace it but the file extension also change. And if there are multiple files in that folder he gives an error that the file already exist.

e.g. i have 200 files with the name "He&llo". and I only want to remove the "&" for all 200 files.

Any tips? the Code i have made is little messy because i am no pro. :)

Thankssss


Explanation textboxen:

Textbox1 = Path
Textbox2 = from "He&llo"
Textbox3 = to "Hello"


------------------------



Public Class Form1


Dim objFolder As Object
Dim strMessage3 As Object
Dim strMessage As String
Dim strMessage2 As String
Dim colFiles As Object
Dim FileSysFull As Object
Dim objFile As String
Dim aString As String




Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim objFSO, objStartFolder, regEx, objFile, objShell, fh2, ofilesys

Timer1.Start()
Label4.Text = ""













'Const StartPath = ("strMessage3")





objShell = CreateObject("Wscript.Shell")

objFSO = CreateObject("Scripting.FileSystemObject")

objFolder = objFSO.GetFolder(TextBox1.Text)

regEx = New RegExp







objShell.CurrentDirectory = TextBox1.Text







'Your pattern here

regEx = TextBox2.Text



colFiles = objFolder.Files

For Each objFile In colFiles


TextBox2.Text = regEx.Replace(objFile.Name, TextBox3.Text)
regEx.Replace(objFile.Name, TextBox3.Text)
'strMessage3 = objFile.Move(objShell.CurrentDirectory)

'TextBox1.Text =
objFile.move(TextBox2.Text)




Next



regEx = Nothing

objFile = Nothing

objStartFolder = Nothing

objFSO = Nothing



If ToolStripProgressBar1.Value = 100 Then
Timer1.Stop()
End If

End Sub
end class


Viewing all articles
Browse latest Browse all 688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>