Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8001253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:02:51+00:00 2026-06-04T16:02:51+00:00

I am running a MATLAB project, which is shared by several users, some running

  • 0

I am running a MATLAB project, which is shared by several users, some running Windows and some running Linux.

In some of the scripts, I need to access files which are in external directories, and which I do not want to add to the MATLAB path.

To accommodate both Linux and Windows, I need to be able to determine the type of OS I’m running, and to set the directory separator accordingly (‘\’ for Windows, ‘/’ for Linux).

I tried

os = getenv('OS')

(which I saw in some official guide),but it returns an empty string.

I could check the first character of ‘pwd’, but that’s pretty ugly, and I expect that there should be something simpler.

Thanks for any suggestions!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:02:52+00:00Added an answer on June 4, 2026 at 4:02 pm

    To use correct directory separator you don’t need to write code to handle different operating systems. filesep gives you the correct directory separator.

    My1stDir = 'Year2012';
    My2ndDir = 'Feb';
    My3rdDir = 'Day03';
    
    MyDir = [ 'mydata', filesep, My1stDir, filesep, My2ndDir, filesep, My3rdDir ];
    

    In Linux you’ll get:

    MyDir =
         mydata/Year2012/Feb/Day03
    

    In Windows you’ll get:

    MyDir =
         mydata\Year2012\Feb\Day03
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm downloading some big files(2GB) and also I'm running a Matlab script which is
I'm running Matlab 7.8.0 under Windows. I am calling an external utility using dos()
I'm completely new to Matlab and I need some help. I'm running a self-organising
I'm running a long simulation in MATLAB that I've realized I need to stop
i have two machines running MATLAB and i need to exchange information(numbers,images) between them,is
I have a C# program which should call Matlab for running a m-file and
I'm running a series of scripts that all import data from different matrix files.
I'm running Matlab 2010 and there's some function I want to run from my
My project is in C, CodeBlocks is my IDE and i´m running on windows
I am currently running repetitions of an experiment that uses MEX files in MATLAB

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.