Hi all,
I'm attempting to create a file path from a file name formed in a for loop because I am having several files to read and process, but the path generated includes a backslash before the extension. How do I get rid of it? Here is the code and output.
The created file path is:
zrdFile =
C:\Users\USER\Documents\Zemax\SAMPLES\Non-sequential\Simulations\Clear_weather_Simulation_zmx_1\.zrd
for k = 1:10
fname = sprintf('Clear_weather_Simulation_zmx_%d',k)
samplesDir = TheApplication.SamplesDir;
fileDir = System.IO.Path.Combine(samplesDir, 'Non-sequential', 'Simulations');
lensFile = System.IO.Path.Combine(fileDir, fname,'.zmx');
zrdFile = System.IO.Path.Combine(fileDir, fname,'.zrd')
ReadZRDFile(TheSystem, lensFile, zrdFile);

 採用された回答

Stephen23
Stephen23 2023 年 2 月 10 日

0 投票

lensFile = System.IO.Path.Combine(fileDir, [fname,'.zmx']);
% ^ ^

1 件のコメント

Prisila Ishabakaki
Prisila Ishabakaki 2023 年 2 月 10 日
Hi Stephen,
It worked out! Thank you.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by