[solved] file name with space

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

Moderators: XnTriq, xnview

lian
Posts: 207
Joined: Wed Nov 24, 2004 8:53 pm
Contact:

[solved] file name with space

Postby lian » Mon Mar 28, 2016 1:27 pm

Hello,
I suppose it's logical that NConvert cannot handle file names with space. Is there any solution included in NConvert other than just use a tool to get rid of the spaces ?
Last edited by lian on Tue Mar 29, 2016 9:21 am, edited 1 time in total.
SF, illustrations et mes BD sur mon blog: http://www.li-an.fr/blog
Windows 10 Home 64 bits

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

Re: file name with space

Postby cday » Mon Mar 28, 2016 2:19 pm

lian wrote:I suppose it's logical that NConvert cannot handle file names with spaces...

There is a limitation, not well documented, on using quotes around filenames with spaces at the same time as using wildcards in inputs, but filenames with spaces can be processed in some circumstances.

For example, the following code converts input files with spaces in the filenames from PNG to JPEG files with the same filename:

Code: Select all

nconvert -out jpeg -o Output\%.jpeg Input\*.png

Input files:
a 00.png
a 01.png
a 02.png
a 03.png

Output files:
a 00.jpg
a 01.jpg
a 02.jpg
a 03.jpg

What do you need to do?

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

Re: file name with space

Postby cday » Mon Mar 28, 2016 2:24 pm

Edit:

That code was run in a situation where relative addressing could be used, so it is not an ideal example...

The following code is a better basic example:

Code: Select all

nconvert -out jpeg -o %.jpeg *.png

lian
Posts: 207
Joined: Wed Nov 24, 2004 8:53 pm
Contact:

Re: file name with space

Postby lian » Mon Mar 28, 2016 2:26 pm

OK, I've got this - XYplorer scripting with NConvert

Code: Select all

 foreach($file, "<get SelectedItemsPathNames |>") { 
    $script= '"C:\Program Files\nconvert\nconvert.exe" '."-ratio -rtype lanczos -rflag orient -quiet -resize longest 950 -out jpeg -o E:\images\Output\%.jpg"." $file";
        run $script; 
        wait 1000;
        }
    end confirm ("Allez à Output ?") == 0;
    goto "E:\images\Output";


The files with spaces in names are not taken in count.
SF, illustrations et mes BD sur mon blog: http://www.li-an.fr/blog
Windows 10 Home 64 bits

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

Re: file name with space

Postby cday » Mon Mar 28, 2016 2:39 pm

I'm not familiar with XYexplorer but if you simply need to use NConvert code to process a directory of images, you could try code derived from the code I posted, but using full paths if necessary.

Note that in a Windows batch file the '%' in your code would need to be doubled to escape the character, if that could be relevant to your problem??

In case of a problem with wildcards and spaces, a FOR loop might ultimately provide a workaround.

lian
Posts: 207
Joined: Wed Nov 24, 2004 8:53 pm
Contact:

Re: file name with space

Postby lian » Mon Mar 28, 2016 2:55 pm

Thanks for your help. I will ask XYplorer forum how to clean the name before using XnConvert.
SF, illustrations et mes BD sur mon blog: http://www.li-an.fr/blog
Windows 10 Home 64 bits

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

Re: file name with space

Postby cday » Mon Mar 28, 2016 7:41 pm

Use of wildcards and quotes in input file names:

A number of previous posts have noted that NConvert input filenames can contain either wildcards or quotes around filenames containing spaces, but not both together.

It has become evident incidentally above that NConvert can, at least in some circumstances, accept filenames containing spaces without the filename being quoted, as in these examples:

Code: Select all

nconvert -out jpeg -o #.jpeg *.png


Code: Select all

nconvert -out jpeg -o %.jpeg *.png

Acceptance of filenames with spaces unquoted seems unexpected and counter intuitive, but if it works... :D

lian
Posts: 207
Joined: Wed Nov 24, 2004 8:53 pm
Contact:

Re: file name with space

Postby lian » Mon Mar 28, 2016 7:50 pm

cday wrote:Use of wildcards and quotes in input file names:

A number of previous posts have noted that NConvert input filenames can contain either wildcards or quotes around filenames containing spaces, but not both together.

It has become evident incidentally above that NConvert can, at least in some circumstances, accept filenames containing spaces without the filename being quoted, as in these examples:

Code: Select all

nconvert -out jpeg -o #.jpeg *.png


Code: Select all

nconvert -out jpeg -o %.jpeg *.png

Thanks. I learned that XYplorer has some functions to "clean" filenames but I'm not a great coder. Maybe I will find something with your suggestions.
SF, illustrations et mes BD sur mon blog: http://www.li-an.fr/blog
Windows 10 Home 64 bits

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

Re: file name with space

Postby cday » Tue Mar 29, 2016 8:52 am

Note that the above statements refer to the use of filenames containing spaces when the folder name either needn't be specified, or does not contain spaces.

The limitation on using wildcards and spaces together referred to above relates to folder paths containing spaces: if wildcards are needed in input file names, avoid using paths containing spaces... [Alternatively, a FOR loop in a batch file may provide a solution.]

lian
Posts: 207
Joined: Wed Nov 24, 2004 8:53 pm
Contact:

Re: file name with space

Postby lian » Tue Mar 29, 2016 9:21 am

OK, solved using a "rename" function from XYplorer - very easy to do.
SF, illustrations et mes BD sur mon blog: http://www.li-an.fr/blog
Windows 10 Home 64 bits


Return to “NConvert”

Who is online

Users browsing this forum: No registered users and 1 guest