-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathslp_directory_list.py
More file actions
57 lines (48 loc) · 1.91 KB
/
slp_directory_list.py
File metadata and controls
57 lines (48 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from pathlib import Path
class SLPDirectoryContents:
NAME = "HetimaSLPDirectoryContents"
DISPLAY_NAME = "SLP Directory Contents"
CATEGORY = "SingleLinePicker"
DESCRIPTION = "Outputs the contents of the directory."
# 毎回読み込む
@classmethod
def IS_CHANGED(cls, **kwargs):
return float("NaN")
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"path": ("STRING", {"multiline": False, "default": "", "tooltip": 'Path to directory'}),
"is_full_path": ("BOOLEAN", {"default": True, "tooltip": "Outputs as full path"}),
"SLP_format": ("BOOLEAN", {"default": False, "tooltip": "Outputs for SLP List View"}),
"prefix": ("STRING", {"multiline": False, "default": "", "tooltip": "Prefix for each output path"}),
},
"optional": {
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("STRING",)
OUTPUT_TOOLTIPS = ("directory contents",)
OUTPUT_NODE = True
FUNCTION = "execute"
def execute(self, path="", is_full_path=True, SLP_format=False, prefix=""):
dir_path = Path(path)
if not path or not dir_path.is_dir():
return ("",)
files = sorted([f for f in dir_path.iterdir()])
result_prefix = ""
if SLP_format:
result_prefix = "#dict\n"
results = []
for file in files:
path_str = ""
if is_full_path:
path_str = str(file.resolve())
else:
path_str = file.name
if prefix != "":
path_str = prefix + path_str
if SLP_format:
path_str = file.name + ":" + path_str
results.append(path_str)
return (result_prefix + "\n".join(results),)