473,671 Members | 2,206 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Capturing File Name As Opposed To The Full File Path

I am using code kindly provided by the Access Web to capture a file
path and insert it into a form. The relevant part of the code follows:
Function GetOpenFile(Opt ional varDirectory As Variant, _
Optional varTitleForDial og As Variant) As Variant
' Here's an example that gets an Access database name.
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant
' Specify that the chosen file must already exist,
' don't change directories when you're done
' Also, don't bother displaying
' the read-only box. It'll only confuse people.
lngFlags = ahtOFN_FILEMUST EXIST Or _
ahtOFN_HIDEREAD ONLY Or ahtOFN_NOCHANGE DIR
If IsMissing(varDi rectory) Then
varDirectory = ""
End If
If IsMissing(varTi tleForDialog) Then
varTitleForDial og = ""
End If

' Define the filter string and allocate space in the "c"
' string Duplicate this line with changes as necessary for
' more file templates.
strFilter = ahtAddFilterIte m(strFilter, _
"All Files (*.*)", "*.*")
' Now actually call to get the file name.
varFileName = ahtCommonFileOp enSave( _
OpenFile:=True, _
InitialDir:=var Directory, _
Filter:=strFilt er, _
Flags:=lngFlags , _
DialogTitle:=va rTitleForDialog )
If Not IsNull(varFileN ame) Then
varFileName = TrimNull(varFil eName)
End If
GetOpenFile = varFileName

Forms!Form1!Fil eTxt = GetOpenFile

End Function
The textbox Form1!FileTxt then shows the full path of the file. In
addition to this, I want to capture the file name only eg. If the path
is "C:\Docs\MyDoc. doc", I want another text box to show "Mydoc".

Can this be easily done?

Any help would be greatly appreciated.
Nov 12 '05 #1
3 3005
In Access 2000 and later, use InstrRev() to find the last backslash
character in the file name. Then use Mid() to get the remainder as the file
name.

In earlier versions, use the trick that Dir() returns just the file name
from a full path.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Wayne Aprato" <cq*******@volc anomail.com> wrote in message
news:4d******** *************** **@posting.goog le.com...
I am using code kindly provided by the Access Web to capture a file
path and insert it into a form. The relevant part of the code follows:
Function GetOpenFile(Opt ional varDirectory As Variant, _
Optional varTitleForDial og As Variant) As Variant
' Here's an example that gets an Access database name.
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant
' Specify that the chosen file must already exist,
' don't change directories when you're done
' Also, don't bother displaying
' the read-only box. It'll only confuse people.
lngFlags = ahtOFN_FILEMUST EXIST Or _
ahtOFN_HIDEREAD ONLY Or ahtOFN_NOCHANGE DIR
If IsMissing(varDi rectory) Then
varDirectory = ""
End If
If IsMissing(varTi tleForDialog) Then
varTitleForDial og = ""
End If

' Define the filter string and allocate space in the "c"
' string Duplicate this line with changes as necessary for
' more file templates.
strFilter = ahtAddFilterIte m(strFilter, _
"All Files (*.*)", "*.*")
' Now actually call to get the file name.
varFileName = ahtCommonFileOp enSave( _
OpenFile:=True, _
InitialDir:=var Directory, _
Filter:=strFilt er, _
Flags:=lngFlags , _
DialogTitle:=va rTitleForDialog )
If Not IsNull(varFileN ame) Then
varFileName = TrimNull(varFil eName)
End If
GetOpenFile = varFileName

Forms!Form1!Fil eTxt = GetOpenFile

End Function
The textbox Form1!FileTxt then shows the full path of the file. In
addition to this, I want to capture the file name only eg. If the path
is "C:\Docs\MyDoc. doc", I want another text box to show "Mydoc".

Can this be easily done?

Any help would be greatly appreciated.

Nov 12 '05 #2
Thanks Allen. This works well.
Nov 12 '05 #3
If the file exist then Dir will return just the filename.

i.e.
?Dir("C:\Docs\M yDoc.doc")
MyDoc.doc
--
Terry Kreft
MVP Microsoft Access
"Wayne Aprato" <cq*******@volc anomail.com> wrote in message
news:4d******** *************** **@posting.goog le.com...
I am using code kindly provided by the Access Web to capture a file
path and insert it into a form. The relevant part of the code follows:
Function GetOpenFile(Opt ional varDirectory As Variant, _
Optional varTitleForDial og As Variant) As Variant
' Here's an example that gets an Access database name.
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant
' Specify that the chosen file must already exist,
' don't change directories when you're done
' Also, don't bother displaying
' the read-only box. It'll only confuse people.
lngFlags = ahtOFN_FILEMUST EXIST Or _
ahtOFN_HIDEREAD ONLY Or ahtOFN_NOCHANGE DIR
If IsMissing(varDi rectory) Then
varDirectory = ""
End If
If IsMissing(varTi tleForDialog) Then
varTitleForDial og = ""
End If

' Define the filter string and allocate space in the "c"
' string Duplicate this line with changes as necessary for
' more file templates.
strFilter = ahtAddFilterIte m(strFilter, _
"All Files (*.*)", "*.*")
' Now actually call to get the file name.
varFileName = ahtCommonFileOp enSave( _
OpenFile:=True, _
InitialDir:=var Directory, _
Filter:=strFilt er, _
Flags:=lngFlags , _
DialogTitle:=va rTitleForDialog )
If Not IsNull(varFileN ame) Then
varFileName = TrimNull(varFil eName)
End If
GetOpenFile = varFileName

Forms!Form1!Fil eTxt = GetOpenFile

End Function
The textbox Form1!FileTxt then shows the full path of the file. In
addition to this, I want to capture the file name only eg. If the path
is "C:\Docs\MyDoc. doc", I want another text box to show "Mydoc".

Can this be easily done?

Any help would be greatly appreciated.

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
715
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit anyway).... Private Sub LogChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) If e.ChangeType = WatcherChangeTypes.Created Then
12
2669
by: Xah Lee | last post by:
would anyone like to translate the following perl script to Python or Scheme (scsh)? the file takes a inpath, and report all html files in it above certain size. (counting inline images) also print a sorted report of html files and their size. (a copy of the script is here: http://xahlee.org/_scripts/check_file_size.pl )
3
12374
by: Xah Lee | last post by:
Split File Fullpath Into Parts Xah Lee, 20051016 Often, we are given a file fullpath and we need to split it into the directory name and file name. The file name is often split into a core part and a extension part. For example: '/Users/t/web/perl-python/I_Love_You.html' becomes
3
408
by: Wayne Aprato | last post by:
I am using code kindly provided by the Access Web to capture a file path and insert it into a form. The relevant part of the code follows: Function GetOpenFile(Optional varDirectory As Variant, _ Optional varTitleForDialog As Variant) As Variant ' Here's an example that gets an Access database name. Dim strFilter As String Dim lngFlags As Long Dim varFileName As Variant
14
2533
by: Brent Burkart | last post by:
I am trying to capture the Windows Authenticated username, but I want to be able to capture the login name that exists in IIS, not Windows. In order to enter my company's intranet through the internet, they have to login. I want to be able to capture that login versus their Windows login because I need to know who they are from any computer rather than only their computer. Any ideas? Thanks
17
2691
by: spentun | last post by:
How can I moitor file which is executed by user or program in window. I need to write a code to monitor file. When user clicks the file(.exe) or is called by program, the name of file will be return to a program. so, excatly, I need to know the name of the executable file that is executed. originally, I try to windows service + FileSystemWatcher. but, There are just created, renamed, deleted, and changed four events in the...
9
7123
by: Martin | last post by:
Using ODBC in a PHP script, I'm trying to read an MS Access MDB file that resides on another computer on my LAN. I'm getting the error: Warning: odbc_connect() : SQL error: The Microsoft Jet database engine cannot open the file '(unknown)'. It is already opened exclusively by another user, or you need permission to view its data., SQL state S1000 in SQLConnect in ... The file is NOT already opened exclusively (or in any other manner)...
65
5065
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but got errors of Failed to open file ./outdir/mytestout.txt. Below is the code: #include <stdio.h>
3
7720
by: =?Utf-8?B?cm9nZXJfMjc=?= | last post by:
hey, I've seen this problem many times over the net, and now I'm one of them. simple code really. File.Move(RemoteFolder, MoveImportedFilesTo); where RemoteFolder = \\192.168.1.99\ftp2users\monday\original1.csv and MoveImportedFilesTo = C:\wow.csv
0
8909
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8596
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4221
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4399
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1801
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.