Dynamic filepath for sftp not allowed
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Home="/folder1/folder2";
Scanname="Exp04_Sample1";
Sftp_path=strcat(Home,"/",Scanname);
fileInfo=dir(s,Sftp_path);
Why does the above not work?
But
fileInfo=dir(s,"/folder1/folder2/Exp04_Sample1");
will work?
1 comentario
Manas Shivakumar
el 9 de Oct. de 2023
Can you describe the variable 's' ? specifically its purpose and its type. I couldn't find MATLAB's dir() function supporting a signature like this dir(var_a, var_b). List folder contents - MATLAB dir - MathWorks India
Respuestas (1)
Vatsal
el 17 de Nov. de 2023
Hi,
The issue seems to be with the 'dir' function. The 'dir' function in MATLAB is used to list files and folders in a directory. When you use 'dir' with a variable as an argument, MATLAB expects the variable to be a string that specifies the name of the file or folder. If the variable is not a string or if the string does not represent a valid file or folder name, 'dir' will not work as expected. In the provided code, 's' and 'Sftp_path' are variables. If 's' is not defined in your code or does not represent a valid file or folder name, the 'dir' function will not work. Similarly, if 'Sftp_path' does not represent a valid file or folder name, the 'dir' function will not work.
I have attached a modified code below:
Home = '/folder1/folder2';
Scanname = 'Exp04_Sample1';
Sftp_path = fullfile(Home, Scanname);
fileInfo = dir(Sftp_path);
In this code, 'fullfile' is used instead of 'strcat' to construct the file path. 'fullfile' constructs a full file specification from the specified folder and file names. It is generally a better choice for constructing file paths because it automatically handles the file separators.
To learn more about the usage and syntax of 'dir' and 'fullfile', you may refer to the MathWorks documentation links below:
I hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre File Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!