import os,sys def list_folders_with_root_files(base_path): root_folders = [] directories_to_check = [base_path] while directories_to_check: current_dir = directories_to_check.pop(0) # Get the listing using xrdfs command try: entries = os.popen(f"xrdfs se01.indiacms.res.in ls {current_dir}").read().splitlines() except Exception as e: print(f"Error accessing {current_dir}: {e}") continue # Separate files and directories files = [entry for entry in entries if entry.endswith('.root')] dirs = [entry for entry in entries if not entry.endswith('.root')] # If there are .root files, save the directory path if files: root_folders.append(current_dir) else: directories_to_check.extend(dirs) return root_folders if __name__ == "__main__": # Check if the user provided the path as an argument if len(sys.argv) != 2: print("Usage: python script.py ") sys.exit(1) # Read the base path from command-line arguments base_path = sys.argv[1] # Get the list of directories containing .root files folders_with_root_files = list_folders_with_root_files(base_path) # Print the paths print("\n\033[33mThe following folders contain root files.\n\033[0m") for folder in folders_with_root_files: print(folder) print("\n\033[33mRun 'python3 getFilesT2.py foldername' for each of them.\n\033[0m")