package file

import (
	"os"
	"path/filepath"
)

func CreateFile(userName, filePath string) error {

	// 获取main.go所在的目录
	currentDir, err := os.Getwd()
	if err != nil {
		return err
	}

	baseDir := filepath.Join(currentDir, "file_library")

	userDir := filepath.Join(baseDir, userName)

	// 检查userName对应的文件夹是否存在，如果不存在则创建
	err = os.MkdirAll(userDir, 0755)
	if err != nil {
		return err
	}

	fullFilePath := filepath.Join(baseDir, userName, filePath)

	file, err := os.Create(fullFilePath)
	if err != nil {
		return err
	}
	defer file.Close()

	return nil
}
