docx2pdf icon indicating copy to clipboard operation
docx2pdf copied to clipboard

Recursively convert all files in a directory tree

Open erelsgl opened this issue 5 years ago • 18 comments

Great tool! Is there a way to convert all files in all subfolders of the given input folder?

erelsgl avatar Feb 20 '20 20:02 erelsgl

Great suggestion! I don't think it works recursively at the moment but that's definitely something we can add.

For the time being you might be able to run this command:

find . -name "*.docx" | xargs -L 1 docx2pdf

In my test on macOS, I got a lot of pop-ups asking to grant permissions so you might want to run docx2pdf on one of the file in the root folder before using the snippet above; hopefully that might reduce the number of permission pop-ups?

Screen Shot 2020-02-20 at 10 04 31 PM

AlJohri avatar Feb 21 '20 03:02 AlJohri

This works in Mac but not in Windows - Windows has no xargs..

erelsgl avatar Feb 21 '20 07:02 erelsgl

Great suggestion! I don't think it works recursively at the moment but that's definitely something we can add.

For the time being you might be able to run this command:

find . -name "*.docx" | xargs -L 1 docx2pdf

In my test on macOS, I got a lot of pop-ups asking to grant permissions so you might want to run docx2pdf on one of the file in the root folder before using the snippet above; hopefully that might reduce the number of permission pop-ups?

Screen Shot 2020-02-20 at 10 04 31 PM

you can add param --keep-active to avoid word alway activate(I find it by run docx2pdf in termimal ,i see hint,hope this is useful to person that process a lot of file ).

zeguangzhang avatar Apr 24 '20 06:04 zeguangzhang

a lot of pop-ups

when you face a lot of pop-ups ,how to solve? waiting for you to reply,thanks

zeguangzhang avatar Apr 24 '20 07:04 zeguangzhang

@zeguangzhang I believe if you run docx2pdf on a single file in a directory, macOS Catalina should ask for a single pop-up giving the program permission to the entire folder. Once that is done, all future files in that same folder shouldn't require any permission pop-ups.

Can you verify if that works for you?

AlJohri avatar Apr 24 '20 16:04 AlJohri

@zeguangzhang I believe if you run docx2pdf on a single file in a directory, macOS Catalina should ask for a single pop-up giving the program permission to the entire folder. Once that is done, all future files in that same folder shouldn't require any permission pop-ups.

Can you verify if that works for you?

accordding to you said,I try it ,but no giving the pop-up permission to the entire folder. i continue believe you said,add some docx files to directory,but still to pop-up always.

zeguangzhang avatar Apr 25 '20 05:04 zeguangzhang

perhaps you can run it on the top level folder once (which will only handle the first level)

and then run it again via xargs to see if that removes the pop-ups?

On Sat, Apr 25, 2020 at 1:17 AM zeguangzhang [email protected] wrote:

@zeguangzhang https://github.com/zeguangzhang I believe if you run docx2pdf on a single file in a directory, macOS Catalina should ask for a single pop-up giving the program permission to the entire folder. Once that is done, all future files in that same folder shouldn't require any permission pop-ups.

Can you verify if that works for you?

accordding to you said,I try it ,but no giving the pop-up permission to the entire folder. i continue believe you said,add some docx files to directory,but still to pop-up always.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AlJohri/docx2pdf/issues/3#issuecomment-619323146, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVJFTDZJOR6WHQ45FCOLPTROJW5HANCNFSM4KYWTP3A .

AlJohri avatar Apr 25 '20 12:04 AlJohri

The first time I ran it, I was overwriting an existing PDF. I had to navigate the "Grant Access" popup flow to let Word access the input file, and then a second popup flow to let Word access the output file. There was no way to change the permission, mid-flow, to apply to the containing folder.

The next time I ran it, the output path didn't exist yet, and the permission popup asked me to grant Word access to the whole folder. That caused subsequent popups to write to that folder to go away.

After that, I still get prompted for each specific input file (even though they're in the same folder I am writing out to, that Word now has permissions to!).

Wondering if there's a way for docx2pdf to request access to the whole folder explicitly (this could be configurable via CLI flags).

ryan-williams avatar May 16 '20 14:05 ryan-williams

Just had a chance to try pointing docx2pdf at a whole folder:

docx2pdf <folder>

it seems that this does what I hoped above: it asks me to grant Word permissions on the whole folder, so that subsequent docx2pdf conversions of individual files in that folder are fully automatic.

It also converts all .docxs to .pdfs "in place" (basenames are kept the same except for the extension), so that's a nice bonus.

Thanks @AlJohri!

ryan-williams avatar May 23 '20 20:05 ryan-williams

The first time I ran it, I was overwriting an existing PDF. I had to navigate the "Grant Access" popup flow to let Word access the input file, and then a second popup flow to let Word access the output file. There was no way to change the permission, mid-flow, to apply to the containing folder.

The next time I ran it, the output path didn't exist yet, and the permission popup asked me to grant Word access to the whole folder. That caused subsequent popups to write to that folder to go away.

After that, I still get prompted for each specific input file (even though they're in the same folder I am writing out to, that Word now has permissions to!).

Wondering if there's a way for docx2pdf to request access to the whole folder explicitly (this could be configurable via CLI flags).

But it is still an error. I still get prompted for each specific input file (even though they're in the same folder I am writing out to, that Word now has permissions to!). Can author fix this error?

HebeTienCoder avatar Mar 19 '22 09:03 HebeTienCoder

I am having the same problem when using convert(). When running the project, Word opens each input file and asks for permission of this specific folder although I granted Word and Pycharm permission for every folder on my Mac. Is there a workaround as long as its not fixed? Can I use docx2pdf <folder path> inside a Python project somehow?

yoKurt94 avatar Aug 11 '22 18:08 yoKurt94

Same problem here, two windows are showing up and I have to give permission to every single file. Would be great if this could be solved!

stocki007 avatar Dec 06 '22 18:12 stocki007

Original comment: Still an issue here in 2023!

Edited comment: I’m having permissions related issues where I’m prompted to give Microsoft Word permission to access a folder or file. Even if I try to use the recommended strategy here.

Steps I have taken and where the issue arises:

  1. Create a parent folder
  2. Run convert() on the parent folder
  3. A pop up appears on Microsoft Word requesting permission to access the parent folder
  4. Provide permission to the parent folder via the pop up
  5. Create a sub folder within the parent folder with new .docx files that need to be converted
  6. Run convert() on the parent folder
  7. Issue: a pop up appears requesting for permission for the sub folder even though permission was granted previously for the parent folder containing the sub folder

Summary: Every time a new sub folder is created within the parent folder where permission was granted to, a new pop up occurs where permission is requested for every new sub folder that was created.

Question: Is it possible to avoid having to provide permission for every new sub folder with .docx files that need to be converted? Running convert() avoids having to provide permission on every file which saves a lot of time, but it is still quite tedious having to provide permission for every sub folder.

nmoton avatar Jan 21 '23 09:01 nmoton

@nmoton not a super helpful comment! please use the +1 feature for this. can you add some more details? are running into permissions issues or something related to recursively converting files in a directory tree?

if its permissions, did the workaround described here not work? https://github.com/AlJohri/docx2pdf/issues/3#issuecomment-633138973

this should grant permissions to the entire folder instead of each file individually

AlJohri avatar Jan 21 '23 14:01 AlJohri

@nmoton not a super helpful comment! please use the +1 feature for this. can you add some more details? are running into permissions issues or something related to recursively converting files in a directory tree?

if its permissions, did the workaround described here not work? #3 (comment)

this should grant permissions to the entire folder instead of each file individually

You’re right about my comment being unhelpful. Sorry about that.

I edited my original comment and provided more context. You can see the changes here.

(Sometimes when using forum boards to ask for help, I can forget that the same communication-based rules apply when asking for help from colleagues. My bad!)

nmoton avatar Jan 21 '23 19:01 nmoton

Hi here, any progress here?

marcglobality avatar May 09 '23 22:05 marcglobality

I am still seeing behavior like @HebeTienCoder describes on my MacOS 12.6 machine. docx2pdf /path/to/dir still requires $n$ permission grants for $n$ .docx files in dir. WITS the workaround described at #3 (comment) did not work.

In my effort to solve this, I have given the following Full Disk Access:

  • Word,
  • my current installation of python, at /opt/homebrew/opt/[email protected]/bin/python3.11, since that's hardcoded into /opt/homebrew/Cellar/docx2pdf/0.1.4/libexec/bin/docx2pdf in my install
  • /usr/bin/osascript since that's how convert.jxa gets called
  • Terminal
  • bash

Despite this, however, docx2pdf still errors or hangs, waiting on manually needing permissions granted.

image

It's not clear to me what permissions Word is lacking, or where it registers the new permissions it gains when I manually click ok.

jasonhemann avatar May 26 '23 15:05 jasonhemann

any updates? this still requires to give permissions over and over again...

chrischma avatar May 10 '24 08:05 chrischma