Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.
27777 Discussions

File path separator for Intel Fortran on Windows


So, I am porting a part of a Fortran code from Linux to Windows which deals with files, and has lines like this:

inquire(file='directory/data', exist=file_exists)

call execute_command_line('cp ../file1 .')

open(unit=outfile, file='directory/data2')



The fortran manual says the string that's given to the file specifier in inquire() or open() statement has to be a valid file path for that system. On Windows obviously the separator is backslash \. So, the file path would be directory\data.


I have tested the inquire statement with both backslash and frontslash and they work, on ifort version 2021 with Windows 10 at least. So my question is, what is the recommended usage: should I use frontslash, or backslash or should I use backslash with an escape? I am asking because I want the code to work on other versions of ifort and if possible on other compilers and other versions of Windows, and I am worried that the backslash might be treated as an escape character. 


Same question for the execute_command_line() call, should I use the backslash, or backslash with escape? (frontslash wouldn't work on command line obviously).


Any help is appreciated.


Labels (1)
0 Kudos
1 Solution
Black Belt Retired Employee

Use backslash. No escape is necessary. Yes, Windows will sometimes accept forward slashes in file paths, but you should not depend on it.

View solution in original post

3 Replies
Black Belt Retired Employee

Use backslash. No escape is necessary. Yes, Windows will sometimes accept forward slashes in file paths, but you should not depend on it.

New Contributor II

If you want a code that works on Linux and Windows, you must use (and write) path management functions (concatenation, split, absolute/relative path ...) like those in the os module in Python. These functions can take in account automatically the particularities of the OS (path separator, disk drive, and so on) and your code will not be OS dependent.


I doubt that the command "cp .../file1 ." will work on Windows. A generic function must be also² written.


Yes you are right the "cp" command does not exist in Windows, so I am going to use GNUwin32 tools to get "cp" on windows command prompt. A generic copy function is present in one of the source files but surprisingly that function is not used much in the rest of the program. The source code of the program is quite old and has been modified by a lot of different people so it's not at all consistent.

There are only a few lines in the program where the backslash-frontslash problem exists, so I am just using #ifdef's to change them. The amount of source code in the program is huge, so I am trying to make as little change as possible.