I'm new in python and i'm strugling with some problem... I'm trying to get absolute path for each files with extenction .cls or .js and after that I'm trying to read them and check if some pattern existing in reading file but i got error that
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\MyUser\\Desktop\\scripts\\TEST_FILE.cls'
with double slashs
import csv
import xml.etree.ElementTree as ET
import xml.dom.minidom as PT
import traceback
import glob, os
import traceback
from pathlib import Path
CLASSES_EXT = '.cls'
JS_EXT = '.js'
CLASSES_PATH = "../src/classes/"
LWC_PATH = "../src/lwc/"
#Function to get list of specific files
#argument
#path - is path where we are looking for files
#extention - extention that we are looking for
def getAbsolutePathForFiles(path, extention):
try:
filesList = os.listdir(path)
retVal = []
for file in filesList:
if(file.endswith(extention)):
retVal.append(os.path.abspath(file))
except Exception:
traceback.print_exc()
return retVal
# function to check if label is using somwhere
def checkIfFileContainsLabel(fileName, label):
try:
filePath = Path(fileName);
print('CO TU ', filePath)
openedFile = open(Path(fileName), 'r+', encoding='utf-8')
#with open(filePath , 'r') as readFile:
for line in readFile:
if label in line:
return True
return False
except Exception:
traceback.print_exc()
#Get list of file in which we will be looking for labels
classesFileList = getAbsolutePathForFiles(CLASSES_PATH, CLASSES_EXT)
jsFileList = getAbsolutePathForFiles(LWC_PATH, JS_EXT)
for pathToFile in classesFileList:
retVal = checkIfFileContainsLabel(pathToFile,"CPT_From")
print('RETVALU ', retVal)