matthewsampson
asked on
take the contents of a textbox and enter a character 4 positions from the end
Hi Guys,
I've got a filepath which is in a textbox - G:\database.mdb
I am doing a 'compact database' function which takes the database path name from the contents of the textbox, compacts the database and then renames it.
I want it to rename it to the same as the original file, but with the addition of 'TC' at the end of the filename.
-----
jro.CompactDatabase("Provi der=Micros oft.Jet.OL EDB.4.0;Da ta Source= """ & textbox1.Text & """ ", _
"Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source= """ & textbox1.Text & "TC" & """ ;Jet OLEDB:Engine Type=5")
-----
The code above works fine, except that it adds the 'TC' after the extention.
I.e: textbox1.text = G:\database.mdb and the new file is called G:\database.mdbTC
What I want is the file to be called D:\databaseTC.mdb
I think it needs to count from the end backwards and then insert the 'TC' just before the 'dot'. (.mdb). This is because there will be different length filenames but they will always end in .mdb.
Any help would be great.
Many Thanks
Matt
I've got a filepath which is in a textbox - G:\database.mdb
I am doing a 'compact database' function which takes the database path name from the contents of the textbox, compacts the database and then renames it.
I want it to rename it to the same as the original file, but with the addition of 'TC' at the end of the filename.
-----
jro.CompactDatabase("Provi
"Provider=Microsoft.Jet.OL
-----
The code above works fine, except that it adds the 'TC' after the extention.
I.e: textbox1.text = G:\database.mdb and the new file is called G:\database.mdbTC
What I want is the file to be called D:\databaseTC.mdb
I think it needs to count from the end backwards and then insert the 'TC' just before the 'dot'. (.mdb). This is because there will be different length filenames but they will always end in .mdb.
Any help would be great.
Many Thanks
Matt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
if you want to split the name, use something like this:
strName = "test.mdb"
strNewName = strName.substring(0,strNam e.LastInde xOf(".") - 1) + "TC" + ".mdb"
Also, you can use the FileInfo object: it has a .name method which gives you the filename without extension. Get this name,
add "TC.mdb" and you're done.
Don't know if the syntax is exact, put a new comment if you can't get it right.
greetings
if you want to split the name, use something like this:
strName = "test.mdb"
strNewName = strName.substring(0,strNam
Also, you can use the FileInfo object: it has a .name method which gives you the filename without extension. Get this name,
add "TC.mdb" and you're done.
Don't know if the syntax is exact, put a new comment if you can't get it right.
greetings
I'd strongly suggest using Joe_Griffith's suggestion, since it's a lot safer (if for some reason there's a platform change or whatever in the future), and also a lot easier to figure out just what's going on.
ASKER
Hi Joe_Griffith,
I've been following your idea.
When using this bit of the code:
----
FileName = Path.GetFileNameWithoutExt ension(tem p)
FileExt = Path.GetExtension(temp)
----
It says that Path is not defined.
Did I miss something?
I've been following your idea.
When using this bit of the code:
----
FileName = Path.GetFileNameWithoutExt
FileExt = Path.GetExtension(temp)
----
It says that Path is not defined.
Did I miss something?
Add
Imports System.IO
or qualify Path as System.IO.Path...
Imports System.IO
or qualify Path as System.IO.Path...
jro.CompactDatabase("Provi
"Provider=Microsoft.Jet.OL
mlmcc