AnsysLink/test/check_ansys_files.py

81 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""
Simple check for ANSYS generated files
"""
import os
import glob
import tempfile
def check_ansys_files():
"""Check for ANSYS generated files"""
print("Checking for ANSYS Generated Files")
print("=" * 40)
# Check common ANSYS temp directories
temp_dir = tempfile.gettempdir()
print(f"System temp directory: {temp_dir}")
# Look for ANSYS directories
ansys_patterns = [
os.path.join(temp_dir, "ANSYS.*"),
os.path.join(temp_dir, "*", "AnsysMech*"),
"*.mechdb",
"*.dat",
"*.inp",
"*.cdb"
]
found_files = []
for pattern in ansys_patterns:
try:
matches = glob.glob(pattern, recursive=True)
for match in matches:
if os.path.isfile(match):
size = os.path.getsize(match)
found_files.append((match, size))
elif os.path.isdir(match):
print(f"ANSYS Directory found: {match}")
# List files in this directory
try:
for root, dirs, files in os.walk(match):
for file in files:
file_path = os.path.join(root, file)
if os.path.isfile(file_path):
size = os.path.getsize(file_path)
found_files.append((file_path, size))
except Exception as e:
print(f" Error listing directory: {e}")
except Exception as e:
print(f"Error with pattern {pattern}: {e}")
# Check current directory for any mesh files
current_dir = os.getcwd()
print(f"\nChecking current directory: {current_dir}")
mesh_extensions = [".mechdb", ".dat", ".inp", ".cdb", ".rst", ".rth"]
for ext in mesh_extensions:
pattern = f"*{ext}"
matches = glob.glob(pattern)
for match in matches:
if os.path.isfile(match):
size = os.path.getsize(match)
found_files.append((match, size))
# Display results
if found_files:
print(f"\nFound {len(found_files)} files:")
for file_path, size in sorted(found_files):
print(f" {file_path} ({size:,} bytes)")
else:
print("\nNo ANSYS mesh files found")
# Check if we have any recent ANSYS processes
print(f"\nNote: ANSYS typically creates temporary files during execution.")
print(f"Files may be cleaned up automatically when the session closes.")
return found_files
if __name__ == "__main__":
check_ansys_files()