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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MoveFile does not work when moving file in a variable 1

Status
Not open for further replies.

mauricionava

Programmer
Jul 8, 2005
209
0
0
US
Hello, I have a form that first it gets the name of the file and stores it in a variable. When I try to do the fso.MoveFile (<souce folder> & <name of the file>),<destination folder> it does not work. If I say "\*.*" it will move all files in the source folder but I only want to move the one in the variable. How can I do that?

Thanks.

Code:
If fldr.files.count >= numberOfFiles Then
   
  For Each fil In fldr.files
  
  If Right(fil.ShortName, 3) = "TIF" Then
      If fil.DateLastModified < oldestDate Then
        oldestFile = fil.path
        oldestDate = fil.DateLastModified
      End If
  End If
  
  Next
  
  ShowFileList = oldestFile
   
  MsgBox oldestFile ' show me file name in a msgbox
  
  filename = oldestFile
  
  fso.MoveFile (sfolder & fso.GetFileName(oldestFile)), dfolder
End If
 
Add the filename to the destination...

Code:
fso.MoveFile sfolder & fso.GetFileName(oldestFile), dfolder & fso.GetFileName(oldestFile)

"If I were to wake up with my head sewn to the carpet, I wouldn't be more surprised than I am right now.
 
I just inherited a program that shells to a batch file to move files. I knew this was stupid, so I'll hang a star on dilettante's post for giving me another idea for improvement of this code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top