I've tried to create a script to loop through a folder and then clip the features. This works. My problem is that my new files are created in the same workspace (in my case Data) but I would like to save them in a different workspace (a geodatabase).

# -*- coding: utf-8 -*-

import arcpy
import os
from arcpy import env

env.overwriteOutput = True

env.workspace = r"C:\Users\Victor\Carto\Data"

clip = r"C:\Users\Victor\Carto\XXX.shp"

list = arcpy.ListFeatureClasses()
print list

for l_list in list:
 filename = os.path.splitext(l_list)[0]
 clip_filename = filename + "_GL"
 arcpy.Clip_analysis(l_list, clip, clip_filename, 0)
  • 1
    Have you tried changing the default workspace, or specifying a target geodatabase in the output path? Right now the software is just doing what you've asked it to do.
    – Vince
    Jun 28, 2016 at 15:43

2 Answers 2


You can specify the path to your geodatabase in the clip tool.

For example, if you have a geodatabase called my_gdb and it's located in c://data

gdb = r'c:/data/my_gdb'
for l_list in list:
  clip_filename = '{0}_GL'.format(os.path.splitext(l_list)[0])
  arcpy.Clip_analysis(l_list, clip, os.path.join(gdb, clip_filename), 0)

If you are trying to put all of the files in one geodatabase, could you just do this?

         for l_list in list:
               filename = code
               clip_filename = code
               # then change workspace to gdb
               arcpy.env.workspace = gdb location
               arcpy.clip code
               # then change workspace back to original workspace
               arcpy.env.workapace = original location

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.