通过自定义模式检查文件命名约定 [英] Check file naming convention by custom pattern

查看:44
本文介绍了通过自定义模式检查文件命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I will be having lot of files incomming into to my server and have to check their convention names accordingly to what will be agreed for each particural file. I am looking for pattern which could be checking them. For example:

SIR 2016-12.xlsx
Silnik_5_30_cos_26122017.xlsx
DIDO 24_05_2017.xlsx
OMO 12-30.csv
MOK 5_3_17.csv
'others unknown file naming conventions at the moment

据我所知,动态部分将始终是每个文件的日期(差异可能是日期/日期时间/时间的格式).我最想知道的是拥有配置文件并使用方括号声明每个文件的预期模式,然后动态放置 日期/日期时间/时间)如下:

From what i know the dynamic part will be always date for each files (the diffrence could be with format of date/datetime/time). What i have on top of my mind is to have config file and declare expecting patterns for each of files using brackets and put dynamic date/datetime/time) as follows:

'within <> are dynamic part

    RTO TR <YYYY-MM>.xlsx           
    Engine-FR_<YYYY_MM_DD>.csv      
    SIR <YYYY-MM>.xlsx
    Silnik_5_30_cos_<DDMMYYYY>.xlsx
    DIDO <DD_MM_YYYY>.xlsx
    OMO <hh-mm>.csv
    MOK <d_M_YY>.csv

后缀具有通用检查器".它可以检查/解码特定的传入文件名,并监督是否通过带有模式的约定约定.您可以提出什么建议,以及如何做到这一点.实例赞赏.如果可能不使用 正则表达式.请注意,我不知道所有不同的传入文件,因为它将在项目步骤中出现,因此最好为新文件名打开解决方案.

Afterwords have "universal checker" which could check/decode specific incomming filename and supervise if passes the agreed convention with pattern. What could you propose and how you would accomplish that. Examples appreciated. If possible not using regular expression. Note that i am not aware about all different incoming files as it will be comming on project step therefore good to have solution opened for new filenames.

推荐答案

我将有很多文件传入服务器,并且必须根据每个特定文件的约定检查它们的约定名称.我正在寻找可以检查它们的模式.

I will be having lot of files incomming into to my server and have to check their convention names accordingly to what will be agreed for each particural file. I am looking for pattern which could be checking them.

您的模板实际上看起来像这样:

Your templates would actually look like this:

   *< YYYY-MM> .xlsx          
    *< YYYY_MM_DD> .csv     
    *< DDMMYYYY> .xlsx
    *< DD_MM_YYYY> .xlsx
    *< hh-mm> .csv
    *< d_M_YY> .csv

    *<YYYY-MM>.xlsx           
    *<YYYY_MM_DD>.csv      
    *<DDMMYYYY>.xlsx
    *<DD_MM_YYYY>.xlsx
    *<hh-mm>.csv
    *<d_M_YY>.csv

其中*表示任意数量的字母,数字或特殊字符".您可能需要其他代码来表示其他规则,例如?"表示仅是一个字母,数字或特殊字符",则可能需要区分任何数字"(其中 包括无"和至少一个".这完全取决于规则.

where * means 'any number of letters, digits or special characters'. You might need other codes to indicate other rules, such as '?' to indicate 'exactly one letter, digit or special character' and you might need to distinguish between 'any number' (which includes none) and 'at least one'.   It all depends on what the rules are.

然后,您的通用检查器"解析模板并根据模板确认文件名.

Your 'universal checker' then parses the templates and confirms the filename against the template.

您为什么不使用正则表达式?那么正则表达式就是模板,并且在通用检查器中不需要其他解析.您将创建一个包含正则表达式,描述以及其他任何内容的类 需要了解模板.将其存储为这些类实例的列表.

Why wouldn't you use regular expressions?  Then the regular expression is the template, and no additional parsing is required in the universal checker. You would create a class that includes the regular expression, a description, and whatever else you need to know about the template.  Store it as a list of those class instances.

构建正则表达式构建工具(使任何用户都可以将其文件名描述为regex并将其添加到列表中)比构建自己的模板解析器要容易得多.

It would be easier to build a regular expression build tool (to enable any user to describe their file name as a regex, and add it to the list) than it would be to build your own template parser.


这篇关于通过自定义模式检查文件命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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