Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STATUS_OBJECT_PATH_NOT_FOUND (0xc000003a) when trying to rename a file #843

Open
akatsudragneel opened this issue Sep 22, 2024 · 1 comment

Comments

@akatsudragneel
Copy link

I am trying to rename a file. So, I have a file named abc.txt in the server: server.com, shareName= share, directory path=dir/1/2/3/4

I am using the below code. I have the session declared as a common variable and I am able to get the file content, upload a file, remove a file, list the files in the above directory. But for some reason gives the error STATUS_OBJECT_PATH_NOT_FOUND although it is available.

public class renameFile {
private static final Logger logger = LoggerFactory.getLogger(renameFile.class);
public static String urlFix(String s) {
return s.replace('/', '\');
}
public static void renameTo(String sessionId, String oldFileName, String newFileName, String path, String shareName) {

    Session session = smbLogin.getSession();
    if (session == null || !Long.toString(session.getSessionId()).equals(sessionId)) {
        logger.error("Invalid session ID");
        return;
    }
    String oldFilePath = path + "/" + oldFileName;
    String newFilePath = path + "/" + newFileName;

    try (DiskShare share = (DiskShare) session.connectShare(shareName)) {
    	FileAllInformation fileInfo = share.getFileInformation(oldFilePath);

        // Access various attributes
        System.out.println("File Name: " + fileInfo.getNameInformation());
        System.out.println("Creation Time: " + fileInfo.getBasicInformation().getCreationTime());
        System.out.println("Last Access Time: " + fileInfo.getBasicInformation().getLastAccessTime());
        System.out.println("Last Write Time: " + fileInfo.getBasicInformation().getLastWriteTime());
        System.out.println("Change Time: " + fileInfo.getBasicInformation().getChangeTime());
        System.out.println("File Attributes: " + fileInfo.getBasicInformation().getFileAttributes());
        System.out.println("File Size: " + fileInfo.getStandardInformation().getEndOfFile());
        System.out.println("File Access Flag: " + fileInfo.getAccessInformation().getAccessFlags());
        
        oldFilePath = urlFix(oldFilePath);
        newFilePath = urlFix(newFilePath);
        
        try (File renameFile = share.openFile(oldFilePath, EnumSet.of(AccessMask.DELETE, AccessMask.GENERIC_WRITE), null, null, SMB2CreateDisposition.FILE_OPEN, null)) {
        	renameFile.rename(newFilePath);
        }
        
    } catch (Exception e) {
        logger.error("An error occurred while renaming the file", e);
    }
}

}

The path is same, just changing the filename. Please help here.

@akatsudragneel
Copy link
Author

Hi All,

I found that the reason is because the actual path is on a DFS, although the path I use above is correct and works for get File, download, upload, it doesn't work for rename. But when I used the same for the underlying dfs path, it worked. So could you please investigate why it is not working?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant