读取文件名 [英] Reading the filename

查看:107
本文介绍了读取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,


我在读取文件的文件名时遇到一个小问题。我想有一个脚本可以读取我的文件并创建相应的文件夹,


要读取的文件如下d124_RD_SF_t01_r05_s089_z121_18grad.txt


文件夹和子文件夹应如下所示


1. / x01_a05_s089 / RD_z121_18grad


2. / x01_c05_s089 / RD_z121_18grad

我有以下代码

Hello All,

I have a small problem in reading the filename of a file. I would like to have a script which could read my file and create the respective folders,

The file to be read is as follows d124_RD_SF_t01_r05_s089_z121_18grad.txt

folders and sub folders should be as follows

1. /x01_a05_s089/RD_z121_18grad

2. /x01_c05_s089/RD_z121_18grad

I have the following code

展开 | 选择 | Wrap | 行号

推荐答案

首先,我认为你将不得不使用正则表达式从您需要的文件名中删除的部分,然后从那里填充目录的名称。


在附注中....我已经更正了您的发布代码标签。您在论坛中有18个帖子,并且之前已将代码标记放入您的帖子中。请在论坛中发布代码时使用代码标记。如果您不知道如何使用它们,那么您可以在此帖子中编辑您的条目并查看它们,或者阅读这篇文章也向您展示。无论哪种方式,请将来使用它们。


为什么不尝试使用正则表达式,如果你需要帮助,请在这里发帖,我们会帮助你。


问候,


Jeff
First, I think you are going to have to use a regular expression to pull the pieces out of the file name that you need and then populate the name of the directory from there.

On a side note.... I have corrected your code tags for your posting. You have 18 posts in the forums and have been had the code tags put into your posts before for you. PLEASE use code tags when posting code in the forums. If you do not know how to use them, then you can either edit your entry in this post and see them, or read this article that also shows you. Either way, please use them in the future.

Why not try working with the Regex''s and if you need help, post here and we will help you.

Regards,

Jeff


名称是固定长度吗?如果是这样可以帮助您使用 substr


--Kevin
Will the name be a fixed length? If so that would help you could use substr.

--Kevin


是的它是固定长度。分别如下定义变量是正确的,


1。
Yes it is fixed length. Is it right to define the variables separately as follows,

1.


这篇关于读取文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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