获得从一个完整或相对路径的文件名知道这个人是不是批次的参数 [英] Get the file name from a full or relative path knowing that this one is not a parameter of the batch
问题描述
当一个文件,使用相对路径或完整路径......,是作为一个批次的参数,我知道如何扩展%1得到的文件名
%〜N1
这是很容易!
不过,我想从哪个是正确的批量处理内部的相对/完整路径获取文件的名称。
请看看我的code。我想扩大%% X(这是在我的情况相对路径)仅考虑其文件名。请你有什么想法?谢谢
关闭@echo
SETLOCAL EnableDelayedExpansion
设置currDir =%CD%
FOR / F令牌= *%%倍In(Lists.out)做(
回声%%点¯x
集filetxt = %% X)
下面是一个例子Lists.out文件,内置的相对路径一些不同的文件。 Lists.out可以由
TEMP \\我file1_X
TEMP \\我file2_X
...............
...
呼应%%〜NX
设置filetxt = %%〜NX)
要治好你的问题。
如果你想扩展太或使用〜NXX
。
When a file, along with relative path or full path..., is given as a parameter of a batch, I know how to expand %1 to get the file name
%~n1
It's quite easy!
Nevertheless, I want to get the name of file from its relative/full path which is right handled inside the batch.
Please look at my code. I'd like to expand %%x (which is a relative path in my case) to take account only its file name. Please do you have any idea? Thanks
@echo off
SETLOCAL EnableDelayedExpansion
set currDir=%CD%
for /f "tokens=*" %%x in (Lists.out) do (
echo %%x
set filetxt=%%x)
Here's an example "Lists.out" file with some different files built-in relative paths. "Lists.out" can be made of
Temp\my file1_X
Temp\my file2_X
...............
...
echo %%~nx
set filetxt=%%~nx)
should cure your problem.
or use ~nxx
if you want the extension too.
这篇关于获得从一个完整或相对路径的文件名知道这个人是不是批次的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!