在powerhell中从文件名中删除路径和扩展名 [英] Removing path and extension from filename in powershell

查看:164
本文介绍了在powerhell中从文件名中删除路径和扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列字符串是文件的完整路径。我只想保存文件名,没有文件扩展名和引导路径。所以从这个:

  c:\temp\myfile.txt 
/ pre>

to

  myfile 

我实际上并没有遍历目录,在这种情况下,像PowerShell的 basename 属性,而是单独处理字符串。

解决方案

有一个方便的.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屋!

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