1

I'm trying to rename a file, and I think I'm going mad my code is simple, I check if the file exists, and if it exists, I rename it. Here is the code :

if (fs.existsSync(__dirname+"/"+req.files.file.path))
{
    fs.rename(__dirname+"/"+req.files.file.path, __dirname+"/app/upload/portfolio/video/"+req.files.file.name, function(err) {
        if (err)
            throw err;
        else
            ....
    });
}

But I get this error (I've replaced the realpath by path/to/file) :

throw err; ^ Error: ENOENT, rename 'path/to/file/filename.mp4'

After a check, I see that the file exists (simply by copy/paste the filepath in the error) What can be the reason of such an issue?

1
  • Are the privileges set right? Commented Dec 28, 2014 at 22:14

1 Answer 1

3

rename can fail with ENOENT not only if the source doesn’t exist, but also if the directory of the destination doesn’t exist. I suspect app/upload/portfolio/video/path/to/file does not exist.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.