How to make search folder script in add-on preference?
The example given is just a regular StringProperty added to the AddonPreferences. Notice that the subtype of the StringProperty is set to DIR_PATH:

import bpy
from bpy.types import Operator, AddonPreferences
from bpy.props import StringProperty, IntProperty

class ExampleAddonPreferences(AddonPreferences):
    bl_idname = __name__

    filepath: StringProperty(
        name=&quot;Example File Path&quot;,
        subtype='DIR_PATH')

    number: IntProperty(
        name=&quot;Example Number&quot;,
        default=4)

    def draw(self, context):
        self.layout.label(text=&quot;This is a preferences view for our add-on&quot;)
        self.layout.prop(self, &quot;filepath&quot;)
        self.layout.prop(self, &quot;number&quot;)

def register():
    bpy.utils.register_class(ExampleAddonPreferences)

def unregister():
    bpy.utils.unregister_class(ExampleAddonPreferences)

if __name__ == &quot;__main__&quot;:
    register()

Further reading

AddonPreferences in the Docs
How to create a Folder Dialog?
How to create a custom UI?