Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how get file knowning only the first letters of the file

Status
Not open for further replies.

Yarka

Technical User
Jan 14, 2007
192
ES
I've a question. How can I do GetFile knowning only the first three letters of the file?

txs
 
You can't use wildcar with the FSO.GetFile method.
One workaround is to enumerate the Files collection of the Folder object and test the Name property.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
ok. I get to do a simple task:
I need put date to a file but I only know the first letters of file's name.
For example:
A day, I'll get a name as qwe.ert.tt and another I'll get a name as qwe.lkffd.klj
How can I do it?
 
When I know all name of the file, my script work good. My problem is when I have a file that I only know the first letters of the name.
My script is as:

Set f = fs.GetFile(strFileName)
strShortName = f.ShortName
...

'get date
strDate = Year(Now) & "." & Right("0" & Month(Now),2) & "." & Right("0" & Day(Now),2) & "."
...

'rename file
f.Name = strDate & f.Name
...
 
Have you tried my suggestion posted 4 May 07 5:05 ?
 
try this:
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\my_folder\")

folder_name  = objfolder.name
icon = vbquestion
For Each aFile In objFolder.Files
    the_file = afile.name
    if left(the_file, 3) = "gwe" then 
       
       msgbox "found gwe.... something"        
       ans = msgbox("is this the file?"& vbcrlf & the_file, vbyesnocancel + icon)
       if ans = vbyes then 
          file_found = "yes"
          exit for 
                  
       end if 

       if ans = vbcancel then 
          exit for
          file_found = "no"
       end if 

    end if 
               
Next
if file_found = "yes" then  
   msgbox "found the file: " & the_file
   
  'this is where you do your operation on the file.
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top