Scratch Folder (Environment setting)

The Scratch Folder environment setting is the location of a folder you can use to write file-based data, such as shapefiles, text files, and layer files.

Writing output to the scratch folder will make your code portable, as this folder will always be available or created when it runs.

Usage notes

  • The Scratch Folder environment is read-only; you cannot set the location directly.
    • If the Scratch Workspace environment has been set, the Scratch Folder environment will reflect this value first.
      • If the Scratch Workspace environment references a geodatabase, the scratch folder will be a folder named scratch in the geodatabase's parent directory.
      • If the Scratch Workspace environment references a folder, the Scratch Folder environment will be set to a folder named scratch in the scratch workspace location.
    • If the Scratch Workspace environment has not been set, the Scratch Folder environment defaults to a folder in the AppData section of the User Profile, typically C:\Users\<user_name>\AppData\Local\Temp\1\scratch.
  • If the scratch folder does not exist, it will be created when the arcpy.env.scratchFolder environment is called.
  • Files written to the Scratch Folder environment are not deleted upon the completion of a script. You must delete them manually.

Dialog syntax

Note:

The Scratch Folder environment is only available in Python and models.

Scripting syntax

arcpy.env.scratchFolder

Script example


import arcpy

print(arcpy.env.scratchFolder)