0

I need to analyze data in some folders.

I do it using Python. I need to move into directories named /a0_0.68410 or /a0_0.68423 , or similar. The names of the folders are all in the form 0.xyztu, 5 digits after the decimal. The folders exist already.

Some lines from the code read:

Intensity_versus_a0_path = os.getcwd() + "/Intensity_Wcm2_versus_a0_10_18_10_19_range.txt"
a0_s = np.loadtxt(Intensity_versus_a0_path, usecols=(1,)) # a0_s[2] is 0.68410 inside the .txt file
top_folder_path = os.getcwd()
for i in range(10):
    a0_folder_path= top_folder_path + "/a0_" + str(a0_s[i])
    os.chdir(a0_folder_path)
    # do_something
    os.chdir(top_folder_path)

I get an error:

  File "charge_state_distr_10000datapoints.py", line 28, in <module>
    os.chdir(a0_folder_path)
FileNotFoundError: [Errno 2] No such file or directory: '/lus/cls01095/work/e674/e674/ouatu/Smiliei_top_folder/Smilei/SIMULATION_RESULTS/10_18_10_19_200ppc_1Dim/a0_0.6841'

The error is because I want to access a folder called a0_6841, which does not exist. The folder which exists indeed is called a0_68410.

What shall I do to access these type of folders, with their name ending in a 0?

I have tried with Decimal module, but it doesn't work (or I don't know how to use it)

velenos14
  • 534
  • 4
  • 13
  • Are all the directory names the same length ? if it is the case you could use print formatting options. Otherwise can a0_s hold strings instead of numbers ? – Malo Feb 10 '21 at 20:39
  • @Malo, all the directory names are the same length a the moment, but later they will contain names like 12.xyztu, so they increase by 1 digit. a0_s is just a container for the 2nd column of a .txt file (filled with numbers) – velenos14 Feb 10 '21 at 20:41
  • @velenos14 : if you cannot work with fixed number of digit after the dot, I am afraid you have to change a0_s type to hold the proper strings directly. – Malo Feb 10 '21 at 20:44
  • @Malo, the number of digits after the dot is fixed and equal to 5 always. The number of digits before the dot might increase later. I might have 12.12345 – velenos14 Feb 10 '21 at 20:47

0 Answers0