Varying folder

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: XnTriq, xnview

Post Reply
kewbsl
Posts: 5
Joined: Tue Nov 10, 2015 12:07 am

Varying folder

Post by kewbsl » Tue Nov 10, 2015 12:24 am

Hi

I'm writing a batch process to merge groups of tiffs into one pdf and I've got it working so that it can cre the file, and everything looks great. One last thing I'm trying to achieve and I can't seem to find it:
there are hundreds of thousands of files in random folders and I want to store them in a new folder structure. So instead of them all being in c:\nconvert\ they should be in subfolders like
c:\nconvert\AB\12345\
c:\nconvert\AB\22334\
c:\nconvert\AB\12233\
c:\nconvert\BG\12233\
c:\nconvert\FC\22334\
and so on. When I set the script to do this i get an error message saying it can't create the file, and I assume this is because it can't create the subdirectories.
Is there any way I can force it to create the folder if it doesn't exist in teh way that - say - xcopy can?

Hm... i suppose I could save it in a temp folder and use xcopy to move it on couldn't i... I might try that if all else fails but I hope it won't be needed!

kewbsl
Posts: 5
Joined: Tue Nov 10, 2015 12:07 am

Re: Varying folder

Post by kewbsl » Tue Nov 10, 2015 12:29 am

Sample code for conversion of one file:

Code: Select all

nconvert.exe -multi -out pdf -c 5 -dpi 72 -o "C:\Users\kewbsl\Desktop\NCONVERT_TEST\SG\560876\1016808_v1.pdf" "U:\07034000\07033640.tif" "U:\07034000\07033641.tif" "U:\07034000\07033642.tif" "U:\07034000\07033643.tif" "U:\07034000\07033644.tif" "U:\07034000\07033645.tif" "U:\07034000\07033646.tif"   >>"C:\Users\kewbsl\Talend\Working Directory\output.txt"
In this example,
NCONVERT_TEST is the main folder
SG\ and 560876\ are subfolders that don't exist yet and I need to create in the process of converting the file

cday
XnThusiast
Posts: 2251
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Varying folder

Post by cday » Tue Nov 10, 2015 1:08 pm

kewbsl wrote:I'm writing a batch process to merge groups of tiffs into one pdf and I've got it working so that it can create the file, and everything looks great. One last thing I'm trying to achieve and I can't seem to find it: there are hundreds of thousands of files in random folders and I want to store them in a new folder structure. So instead of them all being in c:\nconvert\ they should be in subfolders like:

c:\nconvert\AB\12345\
c:\nconvert\AB\22334\
c:\nconvert\AB\12233\
c:\nconvert\BG\12233\
c:\nconvert\FC\22334\

When I set the script to do this I get an error message saying it can't create the file, and I assume this is because it can't create the subdirectories...
In a quick test I just set up, an output folder that didn't exist was created when the script ran, so possibly you need to back up a bit...

I ran this code:

Code: Select all

nconvert -out tiff -o output\test.tiff  test.jpg
These screenshots show the folder that was created, which contains the output file test.tiff :

NConvert_1.png
NConvert_2.png
I should explain that I normally run scripts as batch files .bat in a folder containing a copy of NConvert, as when I first started using the command line I found that was a simple way of ensuring the scripts ran... :wink:

Edit:

Have you tried running your code without this final section:

Code: Select all

>>"C:\Users\kewbsl\Talend\Working Directory\output.txt"
Just a hunch...

kewbsl
Posts: 5
Joined: Tue Nov 10, 2015 12:07 am

Re: Varying folder

Post by kewbsl » Wed Nov 11, 2015 2:04 pm

cday wrote:I ran this code:

Code: Select all

nconvert -out tiff -o output\test.tiff  test.jpg
Thanks. This is interesting. I have experimented a bit. It seems as though it only _doesn't_ work when i use -multi in the code. I can run a conversion in the format you use but as soon as I add one more file and put the -multi switch in there it breaks. Likewise, using -multi in a situation where the folder exists is fine, but where it doesn't it fails, so I think nConvert can't create folders in -multi mode.

cday
XnThusiast
Posts: 2251
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Varying folder

Post by cday » Wed Nov 11, 2015 4:22 pm

kewbsl wrote:It seems as though it only _doesn't_ work when I use -multi in the code. I can run a conversion in the format you use but as soon as I add one more file and put the -multi switch in there it breaks.

Likewise, using -multi in a situation where the folder exists is fine, but where it doesn't it fails, so I think NConvert can't create folders in -multi mode.
Confirmed in my tests:

This code works and creates the required output folder:

Code: Select all

nconvert -out tiff -o output\test.tiff  test.jpg
This code works and creates a multi-page PDF in the same folder as the input files:

Code: Select all

nconvert -multi -out pdf -o test.pdf test_1.jpg test_2.jpg
This code, which requires the output folder to be created when run, fails with the message "Can't create file" :

Code: Select all

nconvert -multi -out pdf -o output\test.pdf test_1.jpg test_2.jpg
I don't see any immediate solution, but propose to report it in a separate post for clarity in the hope of getting Pierre's attention... :wink:

Returning to your overall problem, you need to convert hundreds of thousands of TIFFs in a way you haven't fully outlined, but earlier you mentioned the possibility of creating a temporary folder to hold the output files and then using XCOPY to create the associated output folder when required.

Without knowing exactly how you propose to proceed, I wondered if using MD in your script might be more direct, as in this batch file .bat :

Code: Select all

MD output

nconvert -multi -out pdf -o output\test.pdf test_1.jpg test_2.jpg
That code runs and creates the required output folder just before it is needed...

You could also, of course, use SET to define a variable or variables to possibly make it easier to reuse code repeatedly with different parameter(s) that only need to be entered once.

kewbsl
Posts: 5
Joined: Tue Nov 10, 2015 12:07 am

Re: Varying folder

Post by kewbsl » Thu Nov 12, 2015 9:15 am

cday wrote: Without knowing exactly how you propose to proceed, I wondered if using MD in your script might be more direct, as in this batch file .bat :

Code: Select all

MD output

nconvert -multi -out pdf -o output\test.pdf test_1.jpg test_2.jpg
That code runs and creates the required output folder just before it is needed...

You could also, of course, use SET to define a variable or variables to possibly make it easier to reuse code repeatedly with different parameter(s) that only need to be entered once.
Thanks - I thought of something similar, but there could be several files all in the newly created folder, so the subsequent statements would cause errors unless i did some sort of check to see if it was there already, which would get a bit complicated. I guess it's another option though. It'll give me a lot of errors in the output log but at least it'll be quicker than moving a file from one place to another and deleting the temp file, I should think... Hm. Thanks very much for your expert input and yes, I'll submit the issue on its own thread as a possible bug report.

kewbsl
Posts: 5
Joined: Tue Nov 10, 2015 12:07 am

Re: Varying folder

Post by kewbsl » Thu Nov 12, 2015 9:19 am

kewbsl wrote: yes, I'll submit the issue on its own thread as a possible bug report.
I see you've done that too. Now that's what I call service!

Post Reply