Is there any shortcut for go back to previous folder?

Sometimes I need to navigate among some folders. I need the "go back" in a convenient way, like "cd -". But, this is not supported in Matlab. Is there any way to achieve this? If not, a keyboard shortcut to pop up the recent directory list is OK,too.
Thank you very much.

8 commentaires

You could always write your own version of cd, which could then maintain a stack of recent directories visited. Then it could easily enough support the "cd -" option.
If I understand your comment correctly, I could build a list recording my favor directories. Is that right? I think it is unflexible as "cd -". But this is a solution after all. Thank you.
As far as I understand, to ensure the integrity of the list you need to do all changes between folders with your function. To register changes done with the Current Folder window you will need to use Java.
Do you mean it is impossible to do "cd - " only with Matlab script? @per isakson
I change the current folder in a number of different ways
  • interactively with the Current Folder
  • interactively with the context menu of "the file name tab list"; right click on file name and select "Change Current Folder to" the path of the file
  • and more seldom with the function, cd
afaik: There is no documented way to detect these interactive changes and update the list. Your function can only keep track of the folders that are set with the function itself.
There are 178 articles tagged with Java at Undocumented Matlab. A few lines of Java in the Matlab code is no big deal - given that you find the lines somewhere.
In the Current Folder window there are a left and a right blue arrow. One way would be to find the code that these arrows invoke.
Very helpful. Especially the latent code for the blue arrows and the icon for "the file name tab list". I would like to try.
Embarrassed, I am not familiar with Java script. Navigating among the Java script is hard and frustrating. For me, I prefer to make an own hotkey with Autohotkey for Matlab, by faking a click button on the blue arrow or "file name tab". And wating for updates of Matlab. Thank you for your kindhearted advice. @per isakson (why I can't quote your name)

Connectez-vous pour commenter.

 Réponse acceptée

Cris LaPierre
Cris LaPierre le 24 Mai 2020

0 votes

There is a Back button in the Current Folder toolbox. That takes be back to the folder that was previously the current folder. Does that help or are you specifically looking for a keyboard shortcut?

2 commentaires

Thank you for your advice. I need this. And I am just curious about why Matlab doesn't support "cd - ". It has "cd .././~" yet. Sometimes I was too lazy to move my mouse than keyboard commands, haha.
support for . and .. is present because NTFS and all Unix filesystems literally have entries named . and .. inside them. MATLAB does not need to do any special parsing for either one: it can just ask the operating system to change directory (and then query to find out where it ended up.)
There is special processing for ~ as that is not handled by the operating system. It is, however, only necessary to construct the mapping of ~ to a folder name once at startup time using environment variables HOME, or USERDRIVE and USERPATH, as changes to those are ignored (iirc).
Supporting cd - would require that cd keeps history, which it does not do at the moment. I don't think it would be a difficult change to support one level of history, but it would be different in character than what is already implemented.

Connectez-vous pour commenter.

Plus de réponses (1)

cd ..
can also help to go back to previous folder

6 commentaires

No, this goes to the parent folder, not to the previous folder.
cd /Drive/Shared/Trombone/@pingpong
cd /Drive/531623/home06
cd -
The intent of cd - there would be to cd back to /Drive/Shared/Trombone/@pingpong not to /Drive/531623
Thanks for pointing this out.
cd /abc/def/ghi/jkl/mno
cd /abc/def/ghi
cd -
%this will go back to previous path which is /abc/def/ghi/jkl/mno
cd /abc/def/ghi/jkl/mno
cd /abc/def/ghi
cd ..
%this will go back to one level up of the current path which is /abc/def
Except that
cd -
is not supported :(
cd .. is exactly what you are looking for. Thanks Soon Kiat.
Does anyone have any suggestion about doing the same thing, but this time for going forward in folders ??
cd does not keep any kind of history. It has no idea that you used to be in a folder inside the current folder and want to go back there.

Connectez-vous pour commenter.

Catégories

Produits

Version

R2019a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by