@echo off :: Request admin rights >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" if '%errorlevel%' NEQ '0' ( echo Running as administrator... powershell -Command "Start-Process '%~f0' -Verb RunAs" exit /b )
:: Save the file path set "file_path=%~1"
:: Check if the file path is provided if "%file_path%"=="" ( echo Error: No file selected. pause exit /b )
:: Remove quotes from the file path set "file_path=%file_path:"=%"
:: Check if the file exists if not exist "%file_path%" ( echo Error: File "%file_path%" not found! pause exit /b )
:: Fixed buffer file path set "buffer_file=C:\Scripts\file-path.txt"
:: Save the file path in the buffer file echo %file_path% > "%buffer_file%"
:: Generate output file path set "output_file=%~dp1%~n1.docx"
:: Run Pandoc conversion echo Converting file "%file_path%" to "%output_file%"... pandoc -s -o "%output_file%" "%file_path%"
:: Check if the output file was created if exist "%output_file%" ( echo Success! Created file: "%output_file%" ) else ( echo Error during conversion. )
pause exit /b
Создан для того, чтобы конвертировать через Pandoc формат md в docx. В контекстное меню добавлена строка, активирующая скрипт. Но скрипт всегда возвращает что файл не выбран
@echo off :: Request admin rights >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" if '%errorlevel%' NEQ '0' ( echo Запрос прав администратора... powershell -Command "Start-Process -FilePath '%~f0' -ArgumentList '%*' -Verb RunAs" exit /b )
:: Save the file path set "file_path=%~1"
:: Check if the file path is provided if "%file_path%"=="" ( echo Error: No file selected. pause exit /b )
:: Remove quotes from the file path set "file_path=%file_path:"=%"
:: Check if the file exists if not exist "%file_path%" ( echo Error: File "%file_path%" not found! pause exit /b )
:: Fixed buffer file path set "buffer_file=C:\Scripts\file-path.txt"
:: Save the file path in the buffer file echo %file_path% > "%buffer_file%"
:: Generate output file path set "output_file=%~dp1%~n1.docx"
:: Run Pandoc conversion echo Converting file "%file_path%" to "%output_file%"... pandoc -s -o "%output_file%" "%file_path%"
:: Check if the output file was created if exist "%output_file%" ( echo Success! Created file: "%output_file%" ) else ( echo Error during conversion. )
Вообще-то кавычки убираются уже здесь set file_path=%~1 , но, если по какой-то причине (?) это не работает, обратитесь к данному совету Зачем люди ставят кавычки для здесь set "name=value" понять не смог
@echo off
:: Request admin rights
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
echo Running as administrator...
powershell -Command "Start-Process '%~f0' -Verb RunAs"
exit /b
)
:: Save the file path
set "file_path=%~1"
:: Check if the file path is provided
if "%file_path%"=="" (
echo Error: No file selected.
pause
exit /b
)
:: Remove quotes from the file path
set "file_path=%file_path:"=%"
:: Check if the file exists
if not exist "%file_path%" (
echo Error: File "%file_path%" not found!
pause
exit /b
)
:: Fixed buffer file path
set "buffer_file=C:\Scripts\file-path.txt"
:: Save the file path in the buffer file
echo %file_path% > "%buffer_file%"
:: Generate output file path
set "output_file=%~dp1%~n1.docx"
:: Run Pandoc conversion
echo Converting file "%file_path%" to "%output_file%"...
pandoc -s -o "%output_file%" "%file_path%"
:: Check if the output file was created
if exist "%output_file%" (
echo Success! Created file: "%output_file%"
) else (
echo Error during conversion.
)
pause
exit /b
Создан для того, чтобы конвертировать через Pandoc формат md в docx. В контекстное меню добавлена строка, активирующая скрипт. Но скрипт всегда возвращает что файл не выбран