Search for pdf with specific title and move to a different location on my PC with matlab

5 ビュー (過去 30 日間)
Nathaniel Werner
Nathaniel Werner 2018 年 1 月 22 日
編集済み: Guillaume 2018 年 1 月 23 日
Hello,
I have a folder, let's say 'C:\directory', with a large number of PDF files in it. This folder also houses my matlab code that I am working on. Some of them have the same first few letters, let's say 'abcd' in their titles, while others don't. I want to locate the PDF files with the repeated text in their titles and move them to a new folder, let's say 'C:\directory2'. How can I do this easily, preferably using some combination of ifs and loops? Also, the repeated text will only be at the very beginning of the PDF's titles, not somewhere in the middle if that makes it any easier.
  2 件のコメント
Guillaume
Guillaume 2018 年 1 月 22 日
You seem to be using name and title interchangeably. I understand name as the file name and title as some sort of text within the pdf file.
The former (file name) is easy to do and it's not clear what problem you have.
The latter (identifying some text in a pdf) is harder, potentially extremely hard depending on how the pdf has been generated.
Nathaniel Werner
Nathaniel Werner 2018 年 1 月 23 日
編集済み: Nathaniel Werner 2018 年 1 月 23 日
Hi, sorry, I corrected that so that title is the only term used. The word title here means the file name of the PDF. I'm looking to identify and relocate individual PDF files based on a few characters in their title.

サインインしてコメントする。

回答 (1 件)

Guillaume
Guillaume 2018 年 1 月 23 日
The word title here means the file name of the PDF. I'm looking to identify and relocate individual PDF files based on a few characters in their title.
In that case, isn't it just:
files = dir(fullfile('c:\somepath\', '*abc*.pdf'));
arrayfun(@(file) movefile(fullfile(file.folder, file.name), fullfile('c:\someotherpath', file.name)), files);
  6 件のコメント
Stephen23
Stephen23 2018 年 1 月 23 日
"I found a round-about way of getting what I needed done efficiently."
Guillaume's answer is quite efficient. A "round-about way" is unlikely to be efficient.
Guillaume
Guillaume 2018 年 1 月 23 日
編集済み: Guillaume 2018 年 1 月 23 日
fullfile is used to build paths from various components. If you're not using fullfile for anything that involve files then you're using an unreliable method: either relying on the current folder, using cd, or building paths by string manipulation.
In my answer, I use fullfile to prepend the folder name to the pattern abc.pdf, then pass that to dir which searches for all files that conform to the pattern in the required folder.
And as Stephen says, if your roundabout way is more than the two lines I've written, then it's clearly not as efficient.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by