"exist" command usage question
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone. I wanted to know if it is possible to use a the "exist" command to check if a directory exists, nomater the username of the user eg. check=exist('C:\Users\<user_name>\---\---\---\somedit','dir') Is there a way to somehow get the username or something?
采纳的回答
Walter Roberson
2012-1-14
You can retrieve the username by using getenv('USERNAME') in MS Windows
I would suggest that you probably want to use getenv('HOMEPATH') as the base location for the directory to store files.
0 个评论
更多回答(1 个)
Andreas Goser
2012-1-14
I'd say once you know the file exits on the path, the WHICH command will also be able to find the file - and return the path. Only thing left is to do a reasonable string operation to isolate the username part.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Search Path 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!