Page 1 of 1

[solved] file name with space

Posted: Mon Mar 28, 2016 1:27 pm
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 ?

Re: file name with space

Posted: Mon Mar 28, 2016 2:19 pm
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?

Re: file name with space

Posted: Mon Mar 28, 2016 2:24 pm
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

Re: file name with space

Posted: Mon Mar 28, 2016 2:26 pm
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.

Re: file name with space

Posted: Mon Mar 28, 2016 2:39 pm
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.

Re: file name with space

Posted: Mon Mar 28, 2016 2:55 pm
by lian
Thanks for your help. I will ask XYplorer forum how to clean the name before using XnConvert.

Re: file name with space

Posted: Mon Mar 28, 2016 7:41 pm
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

Re: file name with space

Posted: Mon Mar 28, 2016 7:50 pm
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.

Re: file name with space

Posted: Tue Mar 29, 2016 8:52 am
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.]

Re: file name with space

Posted: Tue Mar 29, 2016 9:21 am
by lian
OK, solved using a "rename" function from XYplorer - very easy to do.