2525import xml .etree .ElementTree as xml
2626from xml .dom import minidom
2727from copy import deepcopy
28+ from pathlib import Path
2829
2930import psychopy
3031from psychopy import data , __version__ , logging
@@ -750,6 +751,11 @@ def getPaths(filePath):
750751 :return: dict of 'asb' and 'rel' paths or None
751752 """
752753 thisFile = {}
754+ # NB: Pathlib might be neater here but need to be careful
755+ # e.g. on mac:
756+ # Path('C:/test/test.xlsx').is_absolute() returns False
757+ # Path('/folder/file.xlsx').relative_to('/Applications') gives error
758+ # but os.path.relpath('/folder/file.xlsx', '/Applications') correctly uses ../
753759 if len (filePath ) > 2 and (filePath [0 ] == "/" or filePath [1 ] == ":" )\
754760 and os .path .isfile (filePath ):
755761 thisFile ['abs' ] = filePath
@@ -775,16 +781,19 @@ def findPathsInFile(filePath):
775781 filePath = filePath .strip ('$' )
776782 filePath = eval (filePath )
777783 except NameError :
778- # List files in director and get condition files
784+ # List files in directory and get condition files
779785 if 'xlsx' in filePath or 'xls' in filePath or 'csv' in filePath :
780786 # Get all xlsx and csv files
781- expPath = self .expPath
782- if 'html' in self .expPath : # Get resources from parent directory i.e, original exp path
783- expPath = self .expPath .split ('html' )[0 ]
784- fileList = (
785- [getPaths (condFile ) for condFile in os .listdir (expPath )
786- if len (condFile .split ('.' )) > 1
787- and condFile .split ('.' )[1 ] in ['xlsx' , 'xls' , 'csv' ]])
787+ expFolder = Path (self .filename ).parent
788+ spreadsheets = []
789+ for pattern in ['*.xlsx' , '*.xls' ,
790+ '*.csv' , '*.tsv' ]:
791+ # NB potentially make this search recursive with
792+ # '**/*.xlsx' but then need to exclude 'data/*.xlsx'
793+ spreadsheets .extend (expFolder .glob (pattern ))
794+
795+ fileList = [getPaths (str (condFile )) for condFile in
796+ spreadsheets ]
788797 return fileList
789798 paths = []
790799 # does it look at all like an excel file?
@@ -845,7 +854,9 @@ def findPathsInFile(filePath):
845854 # Check for any resources not in experiment path
846855 for res in resources :
847856 if srcRoot not in res ['abs' ]:
848- psychopy .logging .warning ("{} is not in the experiment path and so will not be copied to Pavlovia" .format (res ['rel' ]))
857+ psychopy .logging .warning ("{} is not in the experiment path and "
858+ "so will not be copied to Pavlovia"
859+ .format (res ['rel' ]))
849860
850861 return resources
851862
0 commit comments