How to get only file name in 'for' batch command and not file extension

孤街醉人 提交于 2021-01-28 20:34:15

问题


When using this code to upload video's to YouTube, the title that gets named has the file extension at the end (in this case .mp4)

for %%f in (*.mp4) do python --file="%%f" --title="%%f"

回答1:


use for %%f in (*.csv) do echo "%%~nf"

for more info do a for /? .. this is the part that you would liek to see

In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:
%~I         - expands %I removing any surrounding quotes (")
%~fI        - expands %I to a fully qualified path name
%~dI        - expands %I to a drive letter only
%~pI        - expands %I to a path only
%~nI        - expands %I to a file name only
%~xI        - expands %I to a file extension only
%~sI        - expanded path contains short names only
%~aI        - expands %I to file attributes of file
%~tI        - expands %I to date/time of file
%~zI        - expands %I to size of file
%~$PATH:I   - searches the directories listed in the PATH
               environment variable and expands %I to the
               fully qualified name of the first one found.
               If the environment variable name is not
               defined or the file is not found by the
               search, then this modifier expands to the
               empty string


来源:https://stackoverflow.com/questions/33919795/how-to-get-only-file-name-in-for-batch-command-and-not-file-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!