0

EDIT: Here is my complete code.

@echo off
cls
Set "file=%~f1"
Set "f_name=%~n1"
Set "n_name=%f_name: =_%"
Set "target=C:\Users\%USERNAME%\Desktop"
ffmpeg -i "%file%" ^
       -dn ^
       -an ^
       -r 25 ^
       -vcodec hap ^
       -format hap_alpha  ^
       "%target%\%n_name%_Hap_alpha_v1.mov"
pause

I'm using this code to execute something on a given file. But if the file name includes spaces "file name Red_v3.mov" I only get "Red_v3.mov" as output on %%~nxF how to get the name including spaces? So that I can replace " " with "_" using set %file_1% %f_name: =_%

@echo off
set file=%~dpnx1
for %%F in (%file%) do ( 
    Set f_ext=%%~nxF
    Set f_name=%%~nF
    )
echo %file% 
echo %f_ext%
echo %f_name%
pause

Thanks Alex

6
  • Start getting in the habit of using quotes for everything. It protects spaces and special characters. Commented May 1, 2018 at 21:42
  • You know that %~dpnx1 is the same as %~f1 ? Also double quote file names with spaces. Commented May 1, 2018 at 21:42
  • 2
    You were shown that in the answer to your previous question. Commented May 1, 2018 at 21:44
  • Felt really stupid now, thanks Dint realize %~dpnx1 and %~f1 also the "%file%" was under my nose. Commented May 1, 2018 at 21:49
  • Not understanding why you posted that additional code. You can't access the file if you change the space to an underscore. Commented May 1, 2018 at 23:46

1 Answer 1

2

The problem with your code is that you are not using quotes, but there is absolutely no need to set the command line argument to an environmental variable and then use a FOR command to split up the file name again. You already can do that by using the command line argument.

@echo off
set "file=%~f1"
Set "f_ext=%~x1"
Set "f_name=%~n1"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.