#
init -3200 python:
import os
blpi_path = (rf"/Users/{os.getlogin()}/Library/Application Support/Steam/steamapps/workshop/content/331470/508932099/escs/")
def get_directories(dir_path):
directories = []
dir_files = os.listdir(dir_path)
for dir_file in dir_files:
dir = dir_path + dir_file
if os.path.isdir(dir):
directory = {
"path": dir + "/",
"name": dir_file,
}
directories.append(directory)
return directories
def get_files(dir_path):
files = []
dir_files = os.listdir(dir_path)
for dir_file in dir_files:
file_path = dir_path + dir_file
if os.path.isfile(file_path):
renpy_file = file_path.replace(blpi_path, "escs/", 1)
file = {
"path": renpy_file,
"name": os.path.splitext(dir_file)[0]
}
files.append(file)
return files
```
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.
File "/Users/belikovmichael/Library/Application Support/Steam/steamapps/workshop/content/331470/508932099/escs/scripts/images/python/folder_files_handlers.rpy", line 3: invalid syntax
blpi_path = (rf"/Users/{os.getlogin()}/Library/Application Support/Steam/steamapps/workshop/content/331470/508932099/escs/")
^
Ren'Py Version: Ren'Py 7.4.11.2266
Sat Oct 8 04:44:44 2022
```
my_tuple = (rf"first element")
- это невалидная запись. my_tuple = (rf"first element", )
my_string = rf"first element"
если вы хотите получить просто строку. from pathlib import Path
def get_folders(source_path: Path):
return [item for item in source_path.iterdir() if item.is_dir()]
def get_files(source_path: Path):
return [item for item in source_path.iterdir() if item.is_file()]
my_home = Path.home()
my_path = 'Library/Application Support/Steam/steamapps/workshop/content/331470/508932099/escs/'
blpi_path = my_home / my_path
print(f'folders:\n{get_folders(blpi_path)}\n')
print(f'files:\n{get_files(blpi_path)}\n')
Adds support for Python 3, which is recommended for all new games.