Objective:
I want to use Pypandoc
to create a function where the user inputs three arguments being:
(i) an input folder;
(ii) a file format to convert to; and
(iii) an output folder.
Problem:
Before I convert this to a loop to convert multiple files, I want to get it working with one file. The code runs from the following directory:
*C:\workspace\code\doc_check\venv\Scripts\*
The directory containing the files to convert is:
*C:\workspace\code\doc_check\test_folder*
The directory I want to output to is:
*C:\workspace\code\doc_check\output*
Here is my code, followed by the error message I keep receiving:
import pypandoc
import os
# Convert Word document to .md using pypandoc.
def convert(input_dir, output_format, output_dir):
data_files = os.listdir(input_dir)
path_name = os.path.join(input_dir, data_files[0])
output = pypandoc.convert_file(path_name, output_format, outputfile=output_dir + 'test_doc.md')
return output
convert('test_folder', 'md', 'output')
Error message:
C:\workspace\code\doc_check\venv\Scripts\python.exe C:/workspace/code/doc_check/venv/Scripts/doc_check.py
Traceback (most recent call last):
File "C:/workspace/code/doc_check/venv/Scripts/doc_check.py", line 18, in <module>
convert('test_folder', 'md', 'output')
File "C:/workspace/code/doc_check/venv/Scripts/doc_check.py", line 7, in convert
data_files = os.listdir(input_dir)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'test_folder'