ArcGIS 10.3.1; Python 2.7.11
The file DOES exist but reporting that it does not. The syntax looks correct to my newbie eyes.
******************************************************************************************************************
import arcpy
arcpy.env.workspace = "C:\\Users\\kkirkeby\\Desktop\\GIS-4080\\Lesson4_Data\\Lesson4_Data"
#Variables
out_folder_path = 'C:\\Users\\kkirkeby\\Desktop\\GIS-4080\\Lesson4_Data\\Lesson4_Data'
gdb_name = 'L4E5'
gdb_fullPath = out_folder_path +'/' + gdb_name
fclist = arcpy.ListFeatureClasses()
fcIn = 0
fcOut = 0
# Create gdb if it doesn't exist.
if arcpy.Exists(gdb_fullPath):
print "Geodatabase already exist"
else:
print "Geodatabase does not exist. Creating..."
print arcpy.Exists(gdb_fullPath)
print gdb_fullPath
# arcpy.CreateFileGDB_management(out_folder_path, gdb_name)
******************************************************************************************************************
Output:
================================ RESTART ================================
Geodatabase does not exist. Creating...
False
C:\Users\kkirkeby\Desktop\GIS-4080\Lesson4_Data\Lesson4_Data/L4E5
Solved! Go to Solution.
This:
C:\Users\kkirkeby\Desktop\GIS-4080\Lesson4_Data\Lesson4_Data\l4_ex5
Is not a geodatabase/workspace. You are missing the ".gdb" at the end.
C:\Users\kkirkeby\Desktop\GIS-4080\Lesson4_Data\Lesson4_Data\l4_ex5.gdb
can you try concatenating your file with "\\" instead of "/" the inconsistency in the final version may be confusing
not specific to gdb's but
Filenames and file paths in Python
example
>>> f = "file" >>> path = r"c:\temp\text.gdb" >>> full = path+ "\" + f File "<string>", line 1 full = path+ "\" + f ^ SyntaxError: EOL while scanning string literal >>> full = path+ "\\" + f >>> full 'c:\\temp\\text.gdb\\file' >>> full 'c:\\temp\\text.gdb/file' # works but may be confusing
Same result.
You can try:
gdb_name = 'L4E5.gdb' gdb_fullPath = out_folder_path +'\' + gdb_name
Although I typically would construct strings a bit differently using the 'r' literal:
out_folder_path = r'C:\Users\kkirkeby\Desktop\GIS-4080\Lesson4_Data\Lesson4_Data' gdb_name = 'L4E5.gdb' gdb_fullPath = out_folder_path +'\' + gdb_name
Same result:
Also change
gdb_fullPath = out_folder_path +'\\' + gdb_name
print out_folder_path = C:\Users\kkirkeby\Desktop\GIS-4080\Lesson4_Data\Lesson4_Data
print gdb_name = l4_ex5
print gdb_fullPath = C:\Users\kkirkeby\Desktop\GIS-4080\Lesson4_Data\Lesson4_Data\l4_ex5
print arcpy.Exists(gdb_fullPath) = False
This:
C:\Users\kkirkeby\Desktop\GIS-4080\Lesson4_Data\Lesson4_Data\l4_ex5
Is not a geodatabase/workspace. You are missing the ".gdb" at the end.
C:\Users\kkirkeby\Desktop\GIS-4080\Lesson4_Data\Lesson4_Data\l4_ex5.gdb
Well there's 4 hours I'll never get back ...
Thanks. Details, details, details.
You will regain it in the future since you will not likely make that mistake again... Now if we could get people to quit using paths with spaces in them...
I had read the link you listed before and thought I was good. I like your comment about using os.path instead.
Thanks for all your help to date.
Ken