Skip to content

Commit

Permalink
BUG: handle wild cards in Path object
Browse files Browse the repository at this point in the history
  • Loading branch information
jungheejung committed Aug 23, 2024
1 parent ebc05b1 commit a04512a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions spacetop_prep/events/bidsify_alignvideos_ENH.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,25 @@ def alignvideo_format_to_bids(sub, ses, run, task_name, beh_inputdir, bids_dir):
format2bids('sub-0001', 'ses-01', 'run-01', 'task-alignvideos', '/path/to/beh_data', '/path/to/bids_data')
"""
fpath = Path(beh_inputdir) / sub / 'task-alignvideo*' / ses / f'{sub}_{ses}_task-alignvideo*_{run}_beh.csv'

directory_path = Path(beh_inputdir) / sub / f'task-alignvideo*' / ses

# Use glob to match the desired file pattern within that directory
flist = list(directory_path.glob(f'{sub}_{ses}_task-alignvideo*{run}_beh.csv'))

if flist:
fpath = flist[0]
else:
fpath = None

if not fpath.is_file():
# Attempt to find a temporary or alternative file
temp_fpath = Path(beh_inputdir) / sub / 'task-alignvideo*' / ses / f'{sub}_{ses}_task-alignvideo*{run}*TEMP*.csv'

if temp_fpath.is_file():
fpath = temp_fpath

temp_flist = list(directory_path.glob(f'{sub}_{ses}_task-alignvideo*{run}*TEMP*.csv'))
if temp_flist:
fpath = temp_flist[0]
else:
fpath = None
print(f'No behavior data file found for {sub}, {ses}, {run}. Checked both standard and temporary filenames.')
return

Expand Down

0 comments on commit a04512a

Please sign in to comment.