简体   繁体   English

将变化的文件路径列表拆分为所有文件夹和文件名

[英]Split varying list of file paths into all folders and file names

I have a list of a few hundred text file paths varying in number of folders. 我有几百个文本文件路径的列表,这些文件路径的文件夹数量不同。

eg C:/user/folder/subfolder/filename.docx 例如C:/user/folder/subfolder/filename.docx

I need to split these into the file name and folders. 我需要将它们分为文件名和文件夹。 I used to do this by using excel functions "FIND", "LEN", "RIGHT" etc. but this only worked if all paths have the same number of folders which is currently not the case. 我曾经通过使用excel函数“ FIND”,“ LEN”,“ RIGHT”等来做到这一点,但这仅在所有路径具有相同数量的文件夹时才有效,而当前情况并非如此。

How might I complete this in VBA? 如何在VBA中完成此操作? My VBA knowledge is minimal but with this being such a common task, there should be a script out there somewhere that completes this? 我的VBA知识很少,但是由于这是一项常见任务,应该在某个地方完成此任务的脚本吗?

I have searched the web, but it is hard to find a script that completes this. 我已经在网上搜索过,但是很难找到完成此操作的脚本。

Any help whatsoever would be really appreciated. 任何帮助将不胜感激。

Thanks! 谢谢!

If you wanted a VBA approach, something like the following would work: 如果您希望使用VBA方法,则可以执行以下操作:

   Dim fso As FileSystemObject
   Dim path As String
   Dim folder As String
   Dim file As String

   path = "C:/user/folder/subfolder/filename.docx"
   Set fso = New FileSystemObject
   folder = fso.GetParentFolderName(path)
   file = fso.GetFileName(path)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM