How to find a folder in the PC ?

76 ビュー (過去 30 日間)
Peter Kerekes
Peter Kerekes 2018 年 4 月 10 日
コメント済み: Walter Roberson 2019 年 5 月 24 日
I do have got the following problem: I would like to use relative path so I have to find a folder in the PC's D: drive. After I found the location of the file I have to change the current direction to it's.

採用された回答

Rik
Rik 2018 年 4 月 10 日
編集済み: Rik 2018 年 4 月 11 日
You should be able to use cd, which also works with relative paths.
To find the file itself, you can use a recursive search with dir (assuming you have R2016b or newer).
filelist=dir(fullfile('D:','**','Soughtfile.ext'));
filelist will contain a struct with all files on the D drive with the name Soughtfile.ext.
  7 件のコメント
Thomas Dixon
Thomas Dixon 2019 年 5 月 24 日
編集済み: Thomas Dixon 2019 年 5 月 24 日
Hi I have a similar problem. I want to search the entire pc for a FOLDER. This folder is called DataDump\ and is somewhere on the pc (I don't know where). Once in it, there are (random_string)_Hdr.txt files which containt a string of where the data has been storred in the format:
[some number of random lines that dont contain a file path]
[some more random lines that dont contain a file path]
............ D:\[some_random_string].txt
[some more random lines that don't contain a file path]
I want to read this file and selct the entire file path to use to find where the data is. I then want to read the data and eliminate anything that isnt a list of decimal numbers with equal size columns. If this eliminates everything then return ('error no plottable data present'). I then want to be able to collect that data as an array/table to analyse.
In essence I want to send this to a pc where I don't know the file paths/structure. I want it to search that computer and find the _Hdr.txt files assuming this other pc only has one folder on it called ~\DataDump\ . I want it to examin this file and see where it has saved the data from a run which may/may not be in the DataDump\ folder and then I want it to return it me without any of the headings (without knowing if there are any headings or how long they are).
Walter Roberson
Walter Roberson 2019 年 5 月 24 日
Is it certain that the files referred to will always be on D:\ ? Or should the *_Hdr.txt files be search for any occurance of (whitespace)(alphabetic character)(literal colon)(literal backslash) ? Is it certain that the files will not contain UNC paths? And is it certain that the information to look for will not be in URI form such as file:///D/(some_random_string).txt or Google Drive addresses ?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by