Something very strange is happening to me with this script. For some reason the variable% PTH% is giving problems with the quotes, and because of this you can not use PATHs that contain spaces.
@echo off
set CurrDir=%cd%
set BatchFileDir=%~dp0
REM UTF-8
chcp 65001
goto :main
:GetFileData
for /R %CurrDir% %%i in (*.*) do (
Echo Procesando el archivo: "%%i" & set fname=%%~ni
set FullFilePath=%%i
set curr_pth=%%~dpi
set EXTENSION=%%~xi
) & call :renombrar
goto :eof
:renombrar
set "PTH=%curr_pth%"
set "FN=%fname:~0,-1%"
set "EXE=%BatchFileDir%renombrar.exe"
CALL "%EXE%" %PTH% "%FN%" "%EXTENSION%" "%PTH%%FN%%EXTENSION%"
goto :eof
:main
call :GetFileData
goto :eof
If I execute it like that there is no problem as long as the PATH does not have spaces. The .exe enter these parameters:
Path --> argv[1] -->C:\Carpeta1\Carpeta1\Carpeta3\
FileName --> argv[2] -->Nombre del archivo
Extension--> argv[3] -->.extensión
FullPath --> argv[4] -->C:\Carpeta1\Carpeta1\Carpeta3\Nombre del archivo.extensión
The problem appears if I put the variable "% PTH%" in quotes, which I would like to be able to use routes that contain spaces. In that case I have this output in the EXE.
Path --> argv[1] -->C:\Carpeta1\Carpeta1\Carpeta3\" Nombre
FileName --> argv[2] -->del
Extension--> argv[3] -->archivo
FullPath --> argv[4] -->.extensión
The problem is not in the C ++ code. This is the only thing I have currently running on the EXE.
int main(int argc, char *argv[])
{
cout << "Path --> argv[1] -->" << argv[1] << endl;
cout << "FileName --> argv[2] -->" << argv[2] << endl;
cout << "Extension--> argv[3] -->" << argv[3] << endl;
cout << "FullPath --> argv[4] -->" << argv[4] << endl;
return 0;
}
I can not see where the fault may be. Any questions?