Home > Enterprise >  File which include paths to different files
File which include paths to different files

Time:10-06

I want to make a file which include paths, but my problem is that a part of path is not the same e.g. it also includes different daytime which is an element of the path and I don't know how to make it. I tried different ways without any success.

import os
from pathlib import Path

# example path names after daytime this file incudes aroud 12k files 
# path = '/Users/kacper/data_lic/2022-06-10_16-28-28/content_file'
# path = '/Users/kacper/data_lic/2022-09-22_14-20-08/content_file'


for filename in os.listdir(path):
    f = os.path.join(path, filename)
    if os.path.isfile(f):
        out = open('file_paths.txt', 'a') # result file
        out.write(f   '\n')
        out.close()

CodePudding user response:

import glob

path = glob.glob('/Users/kacper/data_lic/*/*') with open('dirs_names.txt', 'w') as 
   fp: for item in path: 
      fp.write('%s\n' % item)
  • Related