How to find a folder in the PC ?

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.

 Respuesta aceptada

Rik
Rik el 10 de Abr. de 2018
Editada: Rik el 11 de Abr. de 2018
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 comentarios

Peter Kerekes
Peter Kerekes el 10 de Abr. de 2018
Yes, but this script has to run in differente PC and in these, the path of the folder are different. That's why I'd likie to find the Folder
Rik
Rik el 10 de Abr. de 2018
You can always try using dir, but that is looking for a needle in a haystack. Isn't there some systematic way you can compose the path?
Maybe it would be helpful to further describe your situation. Do you want to find a file that will always have the same relative path to your script, or should it search your entire computer for that specific file?
Peter Kerekes
Peter Kerekes el 11 de Abr. de 2018
I have to search in my computer. My only information about the file is: there is in the D: drive. But the depth of the path isn't so long. It sholud be in one subfolder or maximum in one subsubfolder. (D:\folder\subfolder\subsubfolder\Soughtfile)
Rik
Rik el 11 de Abr. de 2018
See my edited answer.
Rik
Rik el 14 de Abr. de 2018
Did this suggestion solve your problem? If so, please consider marking it as accepted answer. It will make it easier for other people with the same question to find an answer, as well as give me reputation points. If this didn't solve your question, please comment with what problems you are still having.
Thomas Dixon
Thomas Dixon el 24 de Mayo de 2019
Editada: Thomas Dixon el 24 de Mayo de 2019
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 el 24 de Mayo de 2019
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 ?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Preguntada:

el 10 de Abr. de 2018

Comentada:

el 24 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by