immediate refresh function for cd?

8 ビュー (過去 30 日間)
Jeff Miller
Jeff Miller 2022 年 7 月 23 日
コメント済み: Jeff Miller 2023 年 9 月 8 日
When I run this code in a script:
cd(my_folder_name)
% what goes here?
pause(15)
the current folder window doesn't update until after the script finishes. Is there a command that could go between the cd and the pause so that the current folder window would show the new folder immediately, without waiting for the script to finish?
Thanks,

回答 (1 件)

Paras Gupta
Paras Gupta 2023 年 9 月 7 日
Hi Jeff,
I understand that you want to update the current folder window in MATLAB as soon as the cd function is executed in the script above.
Even though the cd function immediately changes the current directory, the current folder window is updated only after the script finishes executing. There is no direct command within MATLAB to achieve this functionality as the current folder window is managed by the operating system's file explorer.
However, you can try a workaround using the winopen function in MATLAB for Windows operating systems. This function opens a specified folder in a new file explorer window. Here's an example of how you can modify your script:
cd('my_folder_name')
winopen(pwd)
pause(15)
You can also use the system command in MATLAB to execute platform-specific commands for different operating systems. Here's an example that should work across different operating systems:
cd('my_folder_name')
if ispc
system('explorer .');
elseif isunix
system('xdg-open .');
elseif ismac
system('open .');
end
pause(15)
You can refer to the following documents for more information on the functions above:
Hope it helps.
  1 件のコメント
Jeff Miller
Jeff Miller 2023 年 9 月 8 日
@Paras Gupta Thanks for the suggestion, but in my situation winopen and system are awkward because the script works through a number of folders. Opening another explorer window for each new folder leaves the screen unnecessarily cluttered, and closing each explorer window when I'm done with it is a bit complicated and unreliable (see this question). I was hoping there would be something like 'drawnow' that would work to update MATLAB's own folder window...

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by