# LaTeX says it can't find a file but actually it does [duplicate]

I am encountering a weird error when setting a background to the pages of my LaTeX document.

The MWE is the following:

\documentclass[11pt, a4paper]{article}

\usepackage{pgffor} % Per i loop
\usepackage{background}
\usepackage{graphicx}
\usepackage{lipsum}

\newcommand{\sfondo}[1]{\backgroundsetup{angle=0, opacity=0.5, scale=1, contents=\includegraphics{./sfondi dossier/sfondo#1.png}}}

\begin{document}
\foreach \pagenum in {1,...,10}{

\sfondo{\pagenum}

\lipsum[1]

\newpage

}
\end{document}


My IDE is TeXstudio. If I execute the code directly from there, I get no error. If I execute it from a terminal, though, I see that I'm receiving a series of alerts:

LaTeX Warning: File ./sfondi dossier/sfondo1.png' not found on input line 19.

<./sfondi dossier/sfondo1.png, id=4, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo1.png> [1{/var/lib/texmf/fonts/map/pdftex/updmap/pd
ftex.map} <./sfondi dossier/sfondo1.png>]

<./sfondi dossier/sfondo2.png, id=13, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo2.png> [2 <./sfondi dossier/sfondo2.png>]

LaTeX Warning: File ./sfondi dossier/sfondo3.png' not found on input line 19.

<./sfondi dossier/sfondo3.png, id=18, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo3.png> [3 <./sfondi dossier/sfondo3.png>]

<./sfondi dossier/sfondo4.png, id=23, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo4.png> [4 <./sfondi dossier/sfondo4.png>]

LaTeX Warning: File ./sfondi dossier/sfondo5.png' not found on input line 19.

<./sfondi dossier/sfondo5.png, id=28, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo5.png> [5 <./sfondi dossier/sfondo5.png>]

<./sfondi dossier/sfondo6.png, id=33, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo6.png> [6 <./sfondi dossier/sfondo6.png>]

LaTeX Warning: File ./sfondi dossier/sfondo7.png' not found on input line 19.

<./sfondi dossier/sfondo7.png, id=38, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo7.png> [7 <./sfondi dossier/sfondo7.png>]

<./sfondi dossier/sfondo8.png, id=44, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo8.png> [8 <./sfondi dossier/sfondo8.png>]

LaTeX Warning: File ./sfondi dossier/sfondo9.png' not found on input line 19.

<./sfondi dossier/sfondo9.png, id=49, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo9.png> [9 <./sfondi dossier/sfondo9.png>]

<./sfondi dossier/sfondo10.png, id=54, 597.23125pt x 845.1575pt>
<use ./sfondi dossier/sfondo10.png> [10 <./sfondi dossier/sfondo10.png>]


Notice that it doesn't ask me for any input (I read that when pdflatex can't find a file it asks the user to give a new path). Plus, and here's the big thing, actually the PDF comes out fine. In the following screenshot in fact you can see how every page has its own background.

There are two issues though. As first thing, the image doesn't go exactly where it should. As you can see it gets slightly moved horizontally, to the right (the images have the same size of an A4 paper page), so I have to move it through the hshift and vshift attributes in the \backgroundsetup. The shifting is quite precise, but it's not always exactly the same. In the actual document I'm working on, the 100th, last, background, is slightly more tilted to the right than the others.

Also, the compiling is very slow. This surely comes from the size of the pictures and of the final pdf document, but I have the suspect that this error is slowing the compiling even more. Considering that the final tex document will be responsible for a big server-side procedural exportation I'd like to diminish the compilation times of the document and taking out this error seems like being the first step for it.