slash vs. back slash in folder path and file path

1.5k views Asked by At

HI am confused when using slash or back slash when referencing folder path and filer path. It seems to me that folder path uses \ or file path under folder path uses /.

files=np.sort(glob('../export_result/*.csv'))
for f in files:
    print(f)

For example, here is output of a filename:

../export_result\StressNodes_JLFUTop-Job_Dayfr3_to255_72A_4Part_UnDrainSide_DrainTop_NodeStress.csv

I am confused. Is it possible to let them use consistent same either / or \ ?

1

There are 1 answers

2
Levi On

Forward slash and backslash are just separators for separating directories and files in a path. Different systems might use different separators. In Windows, the backslash is used as a separator:

C:\my_folder\myfile.txt

In Mac and Unix/Linux, the slash is used:

/home/david/my_folder/my_file.txt

For better and complete understanding, I suggest that you read this page: Python 3 Quick Tip: The easy way to deal with file paths on Windows, Mac and Linux