You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
505 B
33 lines
505 B
package file
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func FileDe(userName, filePath string) error {
|
|
currentDir, err := os.Getwd()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
baseDir := filepath.Join(currentDir, "file_library")
|
|
fullFilePath := filepath.Join(baseDir, userName, filePath)
|
|
|
|
// 判断文件是否存在
|
|
_, err = os.Stat(fullFilePath)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return os.ErrNotExist
|
|
}
|
|
return err
|
|
}
|
|
|
|
err = os.Remove(fullFilePath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|