Just the file name, not the folder.

PostmanWest
11-21-2003, 02:56 PM
This one willl be easy for you folks...

After executing this:

fs_Files = application.filesearch
With fs_Files
.LookIn = Path
.Filename = "*ectio*.xls"
.Execute

I can then determine filenames found using .foundfiles(i), etc.

But, the .foundfiles code returns the entire file name including the path.

I need to pull out the filename without any path info. I can seem to find a reference to doing that.

Thanks.

PostmanWest
11-21-2003, 03:56 PM
Nevermind. I figured out.

Dangleberry
11-21-2003, 03:56 PM
have a look at the command "mid". you should ba able to work from right to left in a loop to find the first instance of "\", also the function "Len" might come in handy. There is probably a quicker way (anyone?), but unless there are stacks of files it shouldn't make too much difference.

tboltfrank
11-21-2003, 08:24 PM
PostmanWest,

If you figured it out, how about sharing what you came up with.

Timbo
11-22-2003, 01:21 AM
I rekon he had:

strWorkBook = CreateObject("scripting.filesystemobject").getfilename(ThisWorkbook.FullName)

;)

tboltfrank
11-22-2003, 08:29 AM
Timbo,

I see how that gives me the activeworkbook.name, but how do I impliment it into this code, to have my list of file names, not include the path. - Or do I have to use something like Dangleberry's suggestion? - Thanks in advance for yours, or anyones advice.

Sub FilenameList()
X = 0
With Application.FileSearch
.NewSearch
.LookIn = "C:\My Music"
.SearchSubFolders = True
.Filename = "Test"
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
ActiveCell.Offset(X, 0).Value = .FoundFiles(i)
X = X + 1
Next i
Else
MsgBox "There were no matching files found."
End If
End With
End Sub

tboltfrank
11-22-2003, 10:27 AM
I found an answer:
I replaced .FoundFiles(i) with Dir(.FoundFiles(i))
Thanks to Herilane's suggestion, in a similar thread.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum