How to select files based on the name?
2 ビュー (過去 30 日間)
古いコメントを表示
My dataset consists of about 6000 txt files. Every three files have same initial name but diffrent last name.I want to write a code that first select all the three files has same initial name and then combine them in one file and delete them from directory at the same time. This process repeats onward. In the end I will left with 2000 files only.
For example, 123x.txt, 123y.txt, 123z.txt..... it be one group and so on. 123.txt
4 件のコメント
Rik
2022 年 1 月 12 日
Help me help you. I'm not aware of any language where 123 is a first name and y is a last name. You have also already stated this in your question.
What is the pattern here? Is there a separator? Or should the code just attempt to match parts of one name until it finds a substring where there are only 3 matches?
回答 (1 件)
Rik
2022 年 1 月 12 日
First you need to retrieve all file names with dir. Then you can split the file name on the dots with the split function. After that you can use the unique function and generate the 3 source file names and the new file name.
The merging itself depends on the specifics of your files.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!