在批次:从路径和文件名可变的只读文件名 [英] In Batch: Read only the filename from a variable with path and filename

查看:139
本文介绍了在批次:从路径和文件名可变的只读文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在寻找一种方式来采用可变间歇,只解析出的文件名。

I am currently looking for a way to take a variable in batch and only parse out the filename.

例如,我通过我的批处理文件,从中随后被设置为我的源变量其他应用程序-s参数。源文件变量通常包含类似:C:\\ Program Files文件\\ MyApp的\\ Instance.1 \\ DATA \\ filetomove.ext

For example, I pass my batch file a -s parameter from another application which is subsequently set to my source variable. The source file variable typically contains something like: C:\Program Files\myapp\Instance.1\Data\filetomove.ext.

我想从变量,直到第一个\\末读取和结果设置为一个新的变量名,但我一直没能成功地使用了FOR / F条命令。

I assume to read from the end of the variable until the first "\" and set the result to a new variable filename but I have not been able to use the "for /f" commmand successfully.

任何帮助将是非常美联社preciated!

Any help would be much appreciated!

更新:只有标准的XP或Windows 2000/2003可..​​.(不能承担安装资源工具包)

Update: Only standard XP or Windows 2000/2003 available...(can't assume resource kits installed).

推荐答案

如果它进来作为参数传递给脚本,即%1%2,等等,你可以只提取文件名和扩展名改成这样的变量

If its coming in as an argument to the script, i.e. %1, %2, etc, you can extract just the filename and extension into a variable like this:

set FILENAME=%~nxN

其中N是参数的索引。例如,该脚本将呼应首个参数的文件名:

where N is the index of the argument. For example, this script will echo just the filename of the first argument:

@echo off
set FILENAME=%~nx1
echo %FILENAME%

这篇关于在批次:从路径和文件名可变的只读文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆