[solved] file name with space

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

Moderators: XnTriq, helmut, xnview

Post Reply
User avatar
lian
Posts: 226
Joined: Wed Nov 24, 2004 8:53 pm
Contact:

[solved] file name with space

Post by lian »

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: https://www.li-an.fr/
Windows 10 Home 64 bits
cday
XnThusiast
Posts: 3985
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: file name with space

Post by cday »

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: 3985
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: file name with space

Post by cday »

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
User avatar
lian
Posts: 226
Joined: Wed Nov 24, 2004 8:53 pm
Contact:

Re: file name with space

Post by lian »

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: https://www.li-an.fr/
Windows 10 Home 64 bits
cday
XnThusiast
Posts: 3985
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: file name with space

Post by cday »

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.
User avatar
lian
Posts: 226
Joined: Wed Nov 24, 2004 8:53 pm
Contact:

Re: file name with space

Post by lian »

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: https://www.li-an.fr/
Windows 10 Home 64 bits
cday
XnThusiast
Posts: 3985
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: file name with space

Post by cday »

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
User avatar
lian
Posts: 226
Joined: Wed Nov 24, 2004 8:53 pm
Contact:

Re: file name with space

Post by lian »

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: https://www.li-an.fr/
Windows 10 Home 64 bits
cday
XnThusiast
Posts: 3985
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: file name with space

Post by cday »

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.]
User avatar
lian
Posts: 226
Joined: Wed Nov 24, 2004 8:53 pm
Contact:

Re: file name with space

Post by lian »

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