How to use files_crawl

Examples of how to use files_crawl to read an folders structure and get the required files and operate with the obj_file.

Example 1

Test code:

 1# python3
 2
 3### Load library
 4import tikzpy.files_crawl as libfile
 5
 6files = libfile.load_obj_files()
 7
 8### Choose a folder
 9folder = r"../tikzpy_shapes"
10
11### Crawl the folder
12file_obj1 = libfile.read_folder_list_files(folder, "png", prefix = "test_shp_f", max_recursive_level = 0, data = False, case_sensitive = False)
13print( file_obj1)
14
15### Crawl the folder for prefix bird
16file_obj2 = libfile.read_folder_list_files(folder, "png", prefix = "test_shp_c", max_recursive_level = 0, data = False, case_sensitive = False)
17
18print( file_obj2)
19
20### Add the objects
21file_obj3 = file_obj1 + file_obj2
22
23print( file_obj3)
24
25### Print indexed folders
26print( file_obj3.folders)
27
28### Iterate paths
29for x in file_obj3:
30
31    print( x.path)
32
33### Object from zero
34file_obj4 = libfile.load_obj_files()
35
36### Add single path
37path = r"../tikzpy_shapes/test_shp_addpto.tikz.png"
38
39### If the file does not exist will not be add
40idx = file_obj4.set_by_path(path)
41
42if idx < 0:
43    print( "If the file does not exist will not be add: %s" % file_obj4[idx].path)
44else:
45    print( "If the file exist will be add: %s" % file_obj4[idx].path)
46
47### Add single path
48path = r"../tikzpy_shapes/test_shp_addpto.tikz.png"
49
50### If the file exist will be add
51idx = file_obj4.set_by_path(path)
52if idx < 0:
53    print( "If the file does not exist will not be add: %s" % file_obj4[idx].path)
54else:
55    print( "If the file exist will be add: %s" % file_obj4[idx].path)
56
57print( file_obj4)
58
59### Print indexed folders
60print( file_obj3.folders)

This would output:

["['test_shp_fill.tikz.png', 0]"]

["['test_shp_color.tikz.png', 0]"]

["['test_shp_fill.tikz.png', 0]", "['test_shp_color.tikz.png', 0]"]

['C:\\DP\\OneDrive\\001_GDrive_Narfisa\\003_Code\\tikzpy\\tikzpy\\docs\\_examples\\tikzpy_shapes']

C:\DP\OneDrive\001_GDrive_Narfisa\003_Code\tikzpy\tikzpy\docs\_examples\tikzpy_shapes\test_shp_fill.tikz.png

C:\DP\OneDrive\001_GDrive_Narfisa\003_Code\tikzpy\tikzpy\docs\_examples\tikzpy_shapes\test_shp_color.tikz.png

If the file exist will be add: C:\DP\OneDrive\001_GDrive_Narfisa\003_Code\tikzpy\tikzpy\docs\_examples\tikzpy_shapes\test_shp_addpto.tikz.png

If the file exist will be add: C:\DP\OneDrive\001_GDrive_Narfisa\003_Code\tikzpy\tikzpy\docs\_examples\tikzpy_shapes\test_shp_addpto.tikz.png

["['test_shp_addpto.tikz.png', 0]", "['test_shp_addpto.tikz.png', 0]"]

['C:\\DP\\OneDrive\\001_GDrive_Narfisa\\003_Code\\tikzpy\\tikzpy\\docs\\_examples\\tikzpy_shapes']