批量脚本错误图片上传

批量脚本错误图片上传

编写了一个批处理脚本文件,使用 Python 中的 cmd 工具将图像上传到 smugmug smugcli。现在我在创建相册时收到错误。我认为这与我在脚本中已经转义的特殊字符有关,但不知何故我仍然收到错误。

我正在使用 watchdirectory 软件扫描文件夹中的新文件。添加新文件时,该软件会启动一个 .bat 文件并创建要在批处理文件中使用的变量。我的脚本获取文件路径并将其用于将照片(变量)上传到 smugmug 上的相册(变量)。

源代码:

@echo off

@REM set MYDIR= %WD_FILE_D%

setlocal enableDelayedExpansion
set "MYDIR=%WD_FILE_D%"


echo "%MYDIR%"

 FOR /f "tokens=4 delims=\" %%a IN ("%MYDIR%") do  set MYDIR2=%%a

 echo %MYDIR2%
 pause

 
@REM set MYDIR2=%MYDIR2: =^%
@REM set MYDIR2=%MYDIR2:"='%

@REM set "MYDIR2=%MYDIR2:&=^&^%"

@REM set %MYDIR2%=%MYDIR2%

echo "%MYDIR2%"
echo %MYDIR2%

pause

@REM rem Define paths with special characters
set  "path1=Photobooths\2023"
set "path2=%MYDIR2%"

rem Define a function to escape special characters in paths
set "escapeSpecialChars=python -c "import sys, os; print(os.path.normpath(sys.argv[1]))""

rem Concatenate paths with escaped special characters
@REM for /f "usebackq delims=" %%a in (`%escapeSpecialChars% "%path1%"`) do set "escaped_path1=%%a"
for /f "usebackq delims=" %%a in (`%escapeSpecialChars% "%path2%"`) do set "escaped_path2=%%a"
echo %escaped_path1%
set "combined_path=%path1%\%escaped_path2%"

echo Combined path: %combined_path%
@REM set "combined_path=%combined_path:&=^^&^%"

 python -m smugcli mkalbum %combined_path%
 python -m smugcli upload "%WD_FILE%" %combined_path%
pause

错误:

"C:\dslrBooth\ontwikkeld\1604-RAY^&\" 1604-RAY& Press any key to continue . . . "1604-RAY^&" 1604-RAY& Press any key to continue . . . ECHO is off. Combined path: Photobooths\2023\1604-RAY& Creating Album "Photobooths\2023\1604-RAY&". Traceback (most recent call last): File "C:\Users\Bert\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\Bert\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\Bert\AppData\Local\Programs\Python\Python39\lib\site-packages\smugcli\__main__.py", line 4, in <module> smugcli.main() File "C:\Users\Bert\AppData\Local\Programs\Python\Python39\lib\site-packages\smugcli\smugcli.py", line 310, in main run(sys.argv[1:]) File "C:\Users\Bert\AppData\Local\Programs\Python\Python39\lib\site-packages\smugcli\smugcli.py", line 302, in run parsed.func(parsed) File "C:\Users\Bert\AppData\Local\Programs\Python\Python39\lib\site-packages\smugcli\smugcli.py", line 118, in <lambda> func=lambda a, t=node_type: fs.make_node(a.user, a.path, a.p, t, File "C:\Users\Bert\AppData\Local\Programs\Python\Python39\lib\site-packages\smugcli\smugmug_fs.py", line 167, in make_node self._match_or_create_nodes( File "C:\Users\Bert\AppData\Local\Programs\Python\Python39\lib\site-packages\smugcli\smugmug_fs.py", line 102, in _match_or_create_nodes all_nodes.append(all_nodes[-1].get_or_create_child(dir, params)) File "C:\Users\Bert\AppData\Local\Programs\Python\Python39\lib\site-packages\smugcli\smugmug.py", line 292, in get_or_create_child return self._create_child_node(name, params) File "C:\Users\Bert\AppData\Local\Programs\Python\Python39\lib\site-packages\smugcli\smugmug.py", line 253, in _create_child_node raise UnexpectedResponseError( smugcli.smugmug.UnexpectedResponseError: Error creating node "1604-RAY&". Server responded with status code 409: Conflict. Album not found: "Photobooths\2023\1604-RAY&".

相关内容