Hello!
I am trying to loop through a list in python and the script is only processing the first database and not the remainder of the list. Where is the script wrong?
1 # import packages
2 import os, arcpy, time, smtplib
3 # setup workspace and SDE databases in folder
4 for dirpath, dirnames, filenames in os.walk(r'C:\Users\xyz\AppData\Roaming\Esri\Desktop10.7\ArcCatalog\SDE'):
5 for file in dirpath:
6 print filenames
7 string = 'C:/Users/xyz/AppData/Roaming/Esri/Desktop10.7/ArcCatalog/SDE/'
8 new_list = [string + x for x in filenames]
9 print new_list
10 for database in new_list:
11 # Block new connections to the database.
12 print('The database is no longer accepting connections{}'.format(database))
13 arcpy.AcceptConnections(database, False)
14 # Wait 5 minutes
15 time.sleep(5)
16 # Disconnect all users from the database.
17 print("Disconnecting all users")
18 arcpy.DisconnectUser(database, "ALL")
19 # Run the compress tool.
20 print("Running compress")
21 arcpy.Compress_management(database)
22 # Allow the database to begin accepting connections again
23 print("Allow users to connect to the database again")
24 arcpy.AcceptConnections(database, True)
25 # Rebuild indexes in database(s)
26 print("Rebuilding indexes on the system tables")
27 arcpy.RebuildIndexes_management(database, "SYSTEM")
28 # Updating statistics in database(s)
29 print("Updating statistics on the system tables")
30 arcpy.AnalyzeDatasets_management(database, "SYSTEM")
31 print ("Finished")
32 break
33 break
34 break