Borrar filtros
Borrar filtros

add words to the end of a path

5 visualizaciones (últimos 30 días)
Alberto Acri
Alberto Acri el 16 de Jun. de 2023
Comentada: Image Analyst el 16 de Jun. de 2023
Hi! I need to add the string or char my version or my version complete to the end of a path.
I tried this way but I can't find the solution. Thanks for the help!
pdest1 = 'C:\....\....\....\.....';
name = "my version";
% name1 = "my version complete";
strPieces = strsplit(pdest1,"\");
number_places = numel(strPieces);
strPieces(number_places + 1) = name; % or name1
number_places = numel(strPieces);
composition = strcat(strPieces(1:number_places));
final_str = join(composition, "\");
final_char = convertStringsToChars(final_str);
  1 comentario
Stephen23
Stephen23 el 16 de Jun. de 2023
Avoid fiddling around with text like that.
Just use FULLFILE.

Iniciar sesión para comentar.

Respuesta aceptada

Angelo Yeo
Angelo Yeo el 16 de Jun. de 2023
pdest1 = 'C:\....\....\....\.....';
name = "my version";
string(pdest1) + name
ans = "C:\....\....\....\.....my version"
  1 comentario
Image Analyst
Image Analyst el 16 de Jun. de 2023
More robust is to use fullfile like @Stephen23 recommended:
pdest1 = 'C:\....\....\....\.....';
name = "my version";
fullFileName = fullfile(pdest1, name)
fullFileName = "C:\....\....\....\...../my version"
Note, the directions of the slashes doesn't matter in Windows - it will work regardless. It added a forward slash here probably because the server is a Unix server.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Name Construction en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by