复制/提取文件路径的一部分?
如何复制/提取文件路径的一部分?
例如,假设我有以下路径:D:\Programs\Tools\Bin\Somefile.dat,
我如何复制/提取它以使其像这样:
C:\Users\ Bin\Somefile.dat
或
C:\Users\Tools\Bin\Somefile.dat
或
C:\Users\Programs\Tools\Bin\Somefile.dat >
请注意,上面的示例将原始路径的一部分更改为另一个目录。我认为这可能称为扩展名称或其他什么?
PS,我已经知道 ExtractFileName 和 ExtractFilePath 等,无论如何,路径都可以是动态的,因为它不会是硬编码路径,而是不断变化的,所以这些函数可能不好。
谢谢。
How can I copy/extract part of a File path?
For example, say if I have this path: D:\Programs\Tools\Bin\Somefile.dat
how could I copy/extract it to make it like this:
C:\Users\Bin\Somefile.dat
or
C:\Users\Tools\Bin\Somefile.dat
or
C:\Users\Programs\Tools\Bin\Somefile.dat
Notice that the examples above are taking part of the original path, and changing it to another directory. I think this is called Expand name or something maybe??
PS, I already know about ExtractFileName and ExtractFilePath etc, the path anyway could be dynamic in that it wont be a hard coded path, but ever changing, so these functions are likely no good.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用 PathAppend 和 PathExtractElements 函数
try using the PathAppend and PathExtractElements functions
您看过 ExtractFileName 函数吗?一切都为您内置。当然,根据您的路径/文件的来源,您可能需要 ExtractFilePath 或其他相关函数。
Have you looked at the ExtractFileName function? all built in for you. Depending on where your paths/files are coming from of course, you may need the ExtractFilePath, or other related functions.
这是一个快速实现,它返回路径的尾部,包括指定数量的元素。还有一些如何使用它的演示,结果正是您所要求的。不幸的是,我不完全理解您所追求的转换:这可能正是您所追求的,或者可能是完全错误的,这恰好产生了看起来像您的示例的结果:
Here's a quick implementation that returns the TAIL of a path, including the specified number of elements. There's also a bit of demo of how to use it, and the results are exactly the ones you requested. Unfortunately I don't fully understand what transformations you're after: this might be exactly what you're after, or it might be something entirely wrong, that just happens to produce a result that looks like your sample: