def file_exists(session, ds_browser, ds_path, file_name):
 client_factory = session.vim.client.factory
 search_spec = search_datastore_spec(client_factory, file_name)
 search_task = session._call_method(session.vim, 'SearchDatastore_Task', ds_browser, datastorePath=str(ds_path), searchSpec=search_spec)
 try:
  task_info = session._wait_for_task(search_task)
 except vexc.FileNotFoundException:
  return False
 file_exists = (getattr(task_info.result, 'file', False) and (task_info.result.file[0].path == file_name))
 return file_exists

def file_exists ( session , ds_browser , ds_path , file_name ) : client_factory = session . vim . client . factory search_spec = search_datastore_spec ( client_factory , file_name ) search_task = session . _call_method ( session . vim , 'SearchDatastore_Task' , ds_browser , datastorePath = str ( ds_path ) , searchSpec = search_spec ) try : task_info = session . _wait_for_task ( search_task ) except vexc . FileNotFoundException : return False file_exists = ( getattr ( task_info . result , 'file' , False ) and ( task_info . result . file [ 0 ] . path == file_name ) ) return file_exists
tests to see if path is a valid file .