Repository: psychopy/psychopy

Issue:
Temporary Excel files cause errors when syncing to Pavlovia
When editing a spreadsheet in Excel, it would sometimes save a copy of the current file with a `~$` prefix (see https://answers.microsoft.com/en-us/office/forum/office_2007-word/is-in-front-of-my-file-name-open-it/54b19aed-4b16-4f96-a4bc-3a8c5476a164?auth=1)

The facts these files exist and contain a $ sign in their name can cause PsychoPy to fail under a specific configuration, when using dynamic condition files.

The relevant code is this excerpt from _experiment.py:

```
            if '$' in filePath:
                try:
                    filePath = filePath.strip('$')
                    filePath = eval(filePath)
                except NameError:
                    # List files in directory and get condition files
                    if 'xlsx' in filePath or 'xls' in filePath or 'csv' in filePath:
                        # Get all xlsx and csv files
                        expFolder = Path(self.filename).parent
                        spreadsheets = []
                        for pattern in ['*.xlsx', '*.xls', '*.csv', '*.tsv']:
                            # NB potentially make this search recursive with
                            # '**/*.xlsx' but then need to exclude 'data/*.xlsx'
                            spreadsheets.extend(expFolder.glob(pattern))
                        files = []
                        for condFile in spreadsheets:
                            # call the function recursively for each excel file
                            files.extend(findPathsInFile(str(condFile)))
                        return files

```

In my example, my conditions spreadsheet is set to `$condition + '.xlsx'`  which triggers what I assume is a workaround code to find all relevant xlsx files. The problem is that in the recursive call to `findPathsInFile()`, there are now these temporary files with a $ in their name, which will then trigger `eval(filePath)` but fail due to a syntax error, because filePath contains an actual file path and not python code.

You should be able to reproduce the bug using the attached project, by opening one of the spreasheets and entering some new values without saving, leaving Excel open.
[listsDemo.zip](https://github.com/psychopy/psychopy/files/5524574/listsDemo.zip)




Discussion:

Resolving patch:
diff --git a/psychopy/experiment/_experiment.py b/psychopy/experiment/_experiment.py
--- a/psychopy/experiment/_experiment.py
+++ b/psychopy/experiment/_experiment.py
@@ -18,6 +18,8 @@
 
 from __future__ import absolute_import, print_function
 # from future import standard_library
+import re
+
 from past.builtins import basestring
 from builtins import object
 import os
@@ -800,9 +802,8 @@ def findPathsInFile(filePath):
             :param filePath: str to a potential file path (rel or abs)
             :return: list of dicts{'rel','abs'} of valid file paths
             """
-
             # Clean up filePath that cannot be eval'd
-            if '$' in filePath:
+            if filePath.startswith('$'):
                 try:
                     filePath = filePath.strip('$')
                     filePath = eval(filePath)


Test patch: