diff --git a/src/stdlib_io_filesystem.F90 b/src/stdlib_io_filesystem.F90 index 1aa4d0711..2dd477abd 100644 --- a/src/stdlib_io_filesystem.F90 +++ b/src/stdlib_io_filesystem.F90 @@ -68,13 +68,16 @@ subroutine list_dir(dir, files, iostat, iomsg) stat = 0 - if (.not. exists(temp_dir)) then + if (is_windows()) then call run('mkdir '//temp_dir, stat) - if (stat /= 0) then - if (present(iostat)) iostat = stat - if (present(iomsg)) iomsg = "Failed to create temporary directory '"//temp_dir//"'." - return - end if + else + call run('mkdir -p '//temp_dir, stat) + end if + + if (stat /= 0) then + if (present(iostat)) iostat = stat + if (present(iomsg)) iomsg = "Failed to create temporary directory '"//temp_dir//"'." + return end if call run('ls '//dir//' > '//listed_contents, stat) diff --git a/test/io/test_filesystem.f90 b/test/io/test_filesystem.f90 index 4b2323fbe..cd3b74a37 100644 --- a/test/io/test_filesystem.f90 +++ b/test/io/test_filesystem.f90 @@ -221,7 +221,11 @@ subroutine fs_list_dir_one_file_one_dir(error) call test_failed(error, "Creating file 1 in directory '"//temp_list_dir//"' failed."); return end if - call run('mkdir '//temp_list_dir//'/'//dir, iostat=stat) + if (is_windows()) then + call run('mkdir '//temp_list_dir//'\'//dir, iostat=stat) + else + call run('mkdir '//temp_list_dir//'/'//dir, iostat=stat) + end if if (stat /= 0) then call test_failed(error, "Creating dir in directory '"//temp_list_dir//"' failed."); return end if