Ниже приведен код python, содержащий список файлов и их zip-файлы. Единственная файловая база геоданных (файловая база данных), которую мне нужно иметь, называется «данные», поэтому как я могу изменить цикл, чтобы включить только базу данных на основе файлов под названием «Данные»? Чтобы быть более конкретным, база данных геоданных хранится в виде системной папки, содержащей двоичные файлы, которые хранят и управляют пространственными данными. Поэтому мне нужна вся системная папка Data.gdb.Обновление для каждой петли в Python
Большое спасибо
#**********************************************************************
# Description:
# Zips the contents of a folder, file geodatabase or ArcInfo workspace
# containing coverages into a zip file.
# Parameters:
# 0 - Input workspace
# 1 - Output zip file. It is assumed that the caller (such as the
# script tool) added the .zip extension.
#
#**********************************************************************
# Import modules and create the geoprocessor
import sys, zipfile, arcgisscripting, os, traceback
gp = arcgisscripting.create()
# Function for zipping files
def zipws(path, zip):
isdir = os.path.isdir
# Check the contents of the workspace, if it the current
# item is a directory, gets its contents and write them to
# the zip file, otherwise write the current file item to the
# zip file
#
for each in os.listdir(path):
fullname = path + "/" + each
if not isdir(fullname):
# If the workspace is a file geodatabase, avoid writing out lock
# files as they are unnecessary
#
if not each.endswith('.lock'):
# gp.AddMessage("Adding " + each + " ...")
# Write out the file and give it a relative archive path
#
try: zip.write(fullname, each)
except IOError: None # Ignore any errors in writing file
else:
# Branch for sub-directories
#
for eachfile in os.listdir(fullname):
if not isdir(eachfile):
if not each.endswith('.lock'):
# gp.AddMessage("Adding " + eachfile + " ...")
# Write out the file and give it a relative archive path
#
try: zip.write(fullname + "/" + eachfile, \
os.path.basename(fullname) + "/" + eachfile)
except IOError: None # Ignore any errors in writing file
if __name__ == '__main__':
try:
# Get the tool parameter values
#
inworkspace = sys.argv[1]
outfile = sys.argv[2]
# Create the zip file for writing compressed data
#
zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_DEFLATED)
zipws(inworkspace, zip)
zip.close()
# Set the output derived parameter value for models
#
gp.setparameterastext(1, outfile)
gp.AddMessage("Zip file created successfully")
except:
# Return any python specific errors as well as any errors from the geoprocessor
#
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n " + \
str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"
gp.AddError(pymsg)
msgs = "GP ERRORS:\n" + gp.GetMessages(2) + "\n"
gp.AddError(msgs)
Нет, Data.gdb это имя базы данных на основе файлов, и это единственный файл, я хочу на застежку. Все остальные файлы, которые я не хочу включать в zip-файл. – Josh
Если «Data.gdb» - это каталог, то это должна быть аргумент командной строки для этой программы, и все готово. Программирование не требуется. –