1

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'
3
  • The system is looking for a directory inside the current working directory, which you say is Scripts. Since neither of those directories are in the CWD, you need to provide the path like ../../test_folder. Commented Aug 13, 2018 at 14:43
  • Thanks, that worked! How do I specify and output directory and get the output file to take the name of the file it converted? At the moment it's outputting to C:\workspace\code\doc_check and naming the converted file outputtest_doc.md. Commented Aug 13, 2018 at 15:15
  • Well, you're specifying the file name with outputfile=output_dir + 'test_doc.md'. If you want a different file name, you need to specify something other than test_doc.md. Commented Aug 13, 2018 at 15:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.