This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
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)
fullFilePath := filepath.Join(baseDir, userName, filePath)
file, err := os.Create(fullFilePath)
defer file.Close()
return nil