capturegraph.procedures.nodes.filesystem.directories
#
Directory Procedures#
Directory management procedures handle the creation and organization of file system structures within the app's data storage. These provide the foundation for organizing captured data into logical hierarchies of targets and sessions.
Example
from capturegraph.procedures.nodes.filesystem import GetRootDirectory
def capture_procedure():
target = GetRootDirectory() # Get the project root
session = target.new_session("daily") # Create timestamped session
data = session.new_directory("measurements") # Create subfolder
return ProcedureSequence(
label="Daily Capture",
procedures=[
data.new_file("reading").save(UserInputNumber(label="Value")),
]
)
Key Concepts
- Targets: Project-level directories where procedures execute
- Sessions: Timestamped execution containers within targets
- Subdirectories: Organizational folders within sessions
GetRootDirectory
#
Bases: Procedure[PDirectory]
Gets the target root directory for this procedure execution.
Returns the root directory of the capture target where this procedure is executing. Targets are project-level folders (e.g., "My Research Study", "Daily Photos") that users create to organize related data collection.
Example
Source code in capturegraph-lib/capturegraph/procedures/nodes/filesystem/directories.py
NewDirectory
#
Bases: Procedure[PDirectory]
Creates a new subdirectory within a parent directory.
Creates a new directory for organizing captured data. The directory will be created if it doesn't exist, or reused if it already exists.
Attributes:
| Name | Type | Description |
|---|---|---|
parent |
Procedure[PDirectory]
|
The parent directory to create the subdirectory in |
name |
str
|
The name of the new directory to create |
Source code in capturegraph-lib/capturegraph/procedures/nodes/filesystem/directories.py
NewSessionDirectory
#
Bases: Procedure[PDirectory]
Creates a new timestamped session directory for this execution.
Each time a procedure runs in the companion app, it creates a new session with a unique hex-encoded microsecond timestamp (e.g., "timelapse_capture/00063B40E29D696A"). Sessions enable multiple executions of the same procedure within a target, with each execution's data organized separately and chronologically.
Sessions are essential for procedures that will be executed repeatedly, often triggered by the app's notification system. The app uses session timestamps to provide chronological navigation and automatic backup scheduling.
Attributes:
| Name | Type | Description |
|---|---|---|
parent |
Procedure[PDirectory]
|
The parent directory (typically target root) to create the session in |
name |
str
|
The session type name (e.g., "timelapse_capture", "daily_survey") |
Source code in capturegraph-lib/capturegraph/procedures/nodes/filesystem/directories.py
GetFirstSessionDirectory
#
Bases: Procedure[PDirectory]
Gets the first (oldest) session directory with the given name.
Searches through the target's sessions folder to find the earliest timestamped session of the specified type. Useful for accessing baseline data, initial measurements, or checking if a procedure has ever been executed before.
Commonly used with ProcedureCompleted to determine first-time vs. repeat executions.
Attributes:
| Name | Type | Description |
|---|---|---|
parent |
Procedure[PDirectory]
|
The parent directory (typically target root) to search within |
name |
str
|
The session type name to search for |
Source code in capturegraph-lib/capturegraph/procedures/nodes/filesystem/directories.py
GetLastSessionDirectory
#
Bases: Procedure[PDirectory]
Gets the last (most recent) session directory with the given name.
Searches through the target's sessions folder to find the most recent timestamped session of the specified type. Useful for comparing to previous data, building on recent measurements, or implementing session-to-session continuity.
Often used in workflows that reference or compare against recent executions.
Attributes:
| Name | Type | Description |
|---|---|---|
parent |
Procedure[PDirectory]
|
The parent directory (typically target root) to search within |
name |
str
|
The session type name to search for |
Source code in capturegraph-lib/capturegraph/procedures/nodes/filesystem/directories.py
GetUserDirectory
#
Bases: Procedure[PDirectory]
Creates a user-specific subdirectory for per-user configurations.
Useful for collaborative capture scenarios where multiple users share a target but need separate configuration directories. The directory structure is: {parent}/{name}/{user.identifier}/
For example, if name is "config" and user ID is "A1B2C3D4-...", this creates: config/A1B2C3D4-.../
Attributes:
| Name | Type | Description |
|---|---|---|
parent |
Procedure[PDirectory]
|
The parent directory to create the user directory in |
name |
str
|
The base directory name (e.g., "config", "preferences") |
user |
Procedure[PUserID]
|
The user ID procedure providing the unique identifier |