在powerhell中从文件名中删除路径和扩展名 [英] Removing path and extension from filename in powershell
本文介绍了在powerhell中从文件名中删除路径和扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
c:\temp\myfile.txt
/ pre>
to
myfile
我实际上并没有遍历目录,在这种情况下,像PowerShell的
basename $ c $可以使用c>属性,而是单独处理字符串。
解决方案有一个方便的.NET方法:
C:\PS> [io.path] :: GetFileNameWithoutExtension(c:\temp\myfile.txt)
myfile
I have a series of strings which are full paths to files. I'd like to save just the filename, without the file extension and the leading path. So from this:
c:\temp\myfile.txt
to
myfile
I'm not actually iterating through a directory, in which case something like powershell's
basename
property could be used, but rather I'm dealing with strings alone.解决方案There's a handy .NET method for that:
C:\PS> [io.path]::GetFileNameWithoutExtension("c:\temp\myfile.txt") myfile
这篇关于在powerhell中从文件名中删除路径和扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文