Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BIDS tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NTrepo
BIDS tools
Merge requests
!1
new laura folder
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
new laura folder
au620747-main-patch-86964
into
main
Overview
1
Commits
14
Pipelines
0
Changes
1
Merged
Laura Rævsbæk Birch
requested to merge
au620747-main-patch-86964
into
main
1 year ago
Overview
1
Commits
14
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Viewing commit
8e0cc6b0
Prev
Next
Show latest version
1 file
+
32
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
8e0cc6b0
Upload New File
· 8e0cc6b0
Laura Rævsbæk Birch
authored
1 year ago
laura/ntlab_create_folders.py
0 → 100644
+
80
−
0
Options
from
cmath
import
sin
from
genericpath
import
isfile
import
os
import
shutil
,
os
def
create_sourcedata_bids_folders
(
basepath
,
originalpath
):
# find all folders in originalpath
participants
=
os
.
listdir
(
originalpath
)
nSubs
=
len
(
participants
)
# Create sourcedata folder
sourcepath
=
os
.
path
.
join
(
basepath
,
'
sourcedata
'
)
try
:
os
.
mkdir
(
sourcepath
)
except
OSError
:
print
(
sourcepath
+
'
- folder already exists
'
)
# Create code folder
codePath
=
os
.
path
.
join
(
basepath
,
'
code
'
)
try
:
os
.
mkdir
(
codePath
)
except
OSError
:
print
(
codePath
+
'
- folder already exists
'
)
# Create sub folders for both BIDS and sourcedata folders
sIndex
=
1
for
sub
in
participants
:
subFolder
=
os
.
path
.
join
(
basepath
,
'
sub-0
'
+
str
(
sIndex
)
if
sIndex
>=
10
else
'
sub-00
'
+
str
(
sIndex
))
try
:
os
.
mkdir
(
subFolder
)
except
OSError
:
print
(
subFolder
+
'
- folder already exists
'
)
# Get number of session folders for sub
nSes
=
len
(
os
.
listdir
(
sub
))
for
i
in
range
(
1
,
nSes
):
sesFolder
=
os
.
path
.
join
(
subFolder
,
'
ses-0
'
+
str
(
i
)
if
i
>=
10
else
'
ses-00
'
+
str
(
i
))
try
:
os
.
mkdir
(
sesFolder
)
except
OSError
:
print
(
sesFolder
+
'
- folder already exists
'
)
eegFolder
=
os
.
path
.
join
(
sesFolder
,
'
eeg
'
)
try
:
os
.
mkdir
(
eegFolder
)
except
OSError
:
print
(
eegFolder
+
'
- folder already exists
'
)
subSourceFolder
=
os
.
path
.
join
(
sourcepath
,
'
sub-0
'
+
str
(
sIndex
)
if
sIndex
>=
10
else
'
sub-00
'
+
str
(
sIndex
))
try
:
os
.
mkdir
(
subSourceFolder
)
except
OSError
:
print
(
subSourceFolder
+
'
- folder already exists
'
)
sesPath
=
os
.
path
.
join
(
subSourceFolder
,
'
ses-0
'
+
str
(
i
)
if
i
>=
10
else
'
ses-00
'
+
str
(
i
))
try
:
os
.
mkdir
(
sesPath
)
except
OSError
:
print
(
subFolder
+
'
- folder already exists
'
)
#copy files from original folder to sourcedata
for
ses
in
os
.
listdir
(
sub
):
sesCount
=
ses
[
4
:]
for
file
in
os
.
listdir
(
os
.
path
.
join
(
sub
,
ses
,
'
eeg
'
)):
source
=
os
.
path
.
join
(
sub
,
ses
,
'
eeg
'
,
file
)
session
=
'
ses-0
'
+
str
(
sesCount
)
destination
=
os
.
path
.
join
(
subSourceFolder
,
session
,
file
)
# if os.path.isfile(file):
# shutil.copy(sub, sesPath)
if
os
.
path
.
isfile
(
source
):
shutil
.
copy
(
source
,
destination
)
subFiles
=
os
.
listdir
(
subSourceFolder
)
for
file
in
subFiles
:
filePath
=
os
.
path
.
join
(
subSourceFolder
,
file
)
shutil
.
move
(
filePath
,
sesPath
)
sIndex
=
sIndex
+
1
\ No newline at end of file
Loading