How to copy a file to portable drive root with cocoa? - cocoa

I've tried the following
[[NSFileManager defaultManager] copyItemAtPath:#"whatever.txt"
toPath:#"/Volumes/MyDrive" error:&copyError];
This gives me the error "The operation couldn’t be completed. File exists"
If I try to copy it to "/Volumes/MyDrive/testFolder" everything copies to testFolder just fine.

I've tried the following
[[NSFileManager defaultManager] copyItemAtPath:#"whatever.txt"
toPath:#"/Volumes/MyDrive" error:&copyError];
This gives me the error "The operation couldn’t be completed. File exists"
First, as KennyTM already told you, the error message is telling you one possible cause of the problem: The file already exists. The destination must not exist; you must either delete it or give a different name for the destination.
Second, there is another possible cause of the problem: You only specified the destination folder, not the complete destination path. You must specify the complete destination path, including the destination filename. Quoth the documentation:
“When a file is being copied, the destination path must end in a filename—there is no implicit adoption of the source filename.”
If you want the copy to have the pathname /Volumes/MyDrive/whatever.txt, that's the pathname you need to pass.
Also, don't forget to check whether the copy succeeded before you attempt to look at the error object. You should only look at the error object if the copy failed.
If I try to copy it to "/Volumes/MyDrive/testFolder" everything copies to testFolder just fine.
I think you'll find that testFolder is, in fact, a file—specifically, it's the copy of whatever.txt.

Isn't the error very clear? "The operation couldn’t be completed. File exists". The doc of -copyItemAtPath:… states that:
The file specified in srcPath must exist, while dstPath must not exist prior to the operation.
You need to call -removeItemAtPath:error: to remove the destination file if you want to override it.

Related

Windows 10 create a softlink to a file

On Windows 10 I am trying to create a soft link to a file through command prompt opened as an Administrator.
mklink "E:\Folder A\Folder B" "E:\Folder A\Folder C\bibliography.bib"
...where I want to create a soft link to bibliography.bib file into a folder B.
This throws me an error Access denied
What could be the reason?
Had to modify my command to
mklink "E:\Folder A\Folder B\bibliography.bib" "E:\Folder A\Folder C\bibliography.bib"
first of all we can create symbolic link from empty directory to file or visa versa - from empty file to directory via FSCTL_SET_REPARSE_POINT - this is legal and will be work. and we can work with target file (or directory) through this symlink. say in case target is file - we can open and read it as file. but any file browser will be incorrect work with such symlink, because it will be use source file attribute FILE_ATTRIBUTE_DIRECTORY - as result try work with file like with directory or visa versa. because this exist sense use only file -> file or directory -> directory symbolic links (the src and target have the same FILE_ATTRIBUTE_DIRECTORY attribute - both have or not have)
also the mklink assume that symbolic link to be created file - yet not exist. internally it use NtCreateFile with FILE_CREATE disposition. as result we got error, if file already exist. if directory already exist and in call NtCreateFile we not use option FILE_DIRECTORY_FILE (mklink use this option when we use /D switch) - we got STATUS_FILE_IS_A_DIRECTORY error. (The file that was specified as a target is a directory and the caller specified that it could be anything but a directory.). but mklink before display error message, first convert it to win32 error code, and it converted to.. ERROR_ACCESS_DENIED. as result we and view Access denied message, despite the error have nothing common with access denied
if we want create symlink to file via mklink, we need select yet not existing file name(path) as symbolic link to be created

Srcipt vbs, moveFolder return Permission denied

Option Explicit
dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists("C:\Users\michal\Desktop\mv_files_backup") then
fso.MoveFolder "C:\Users\michal.glowacki\Desktop\mv_files_backup\*.*", "\\192.168.10.245\backup\servers\backup_server"
Else
wscript.echo "doesn't exist"
End If
When I try run this script I have error:
Permission denied 800A0046
but when I change MoveFolder to CopyFolder script works correctly. Why I can't use function MoveFolder ?
From MSDN:
If source contains wildcards or destination ends with a path separator
( \ ), it is assumed that destination specifies an existing folder in
which to move the matching files. Otherwise, destination is assumed to
be the name of a destination folder to create. In either case, three
things can happen when an individual folder is moved:
If destination does not exist, the folder gets moved. This is the
usual case.
If destination is an existing file, an error occurs.
If destination is a directory, an error occurs.
An error also occurs if a wildcard character that is used in source
doesn't match any folders. The MoveFolder method stops on the first
error it encounters. No attempt is made to roll back any changes made
before the error occurs.
I've marked in bold the parts that explain your problem. Because your destination doesn't end with a trailing backslash, your script is attempting to create the folder, and failing. Try it with a \ added to the end of the destination and report back if it still doesn't work.
Try this:
fso.MoveFolder "C:\Users\michal.glowacki\Desktop\mv_files_backup", "\\192.168.10.245\backup\servers\backup_server\"

hadoop MultipleOutputs to absolute path , but file is already being created by other attempt

I use MultipleOutputs to output data to some absolute paths, instead of a path relative to OutputPath.
Then, i get the error:
Error: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException): Failed to create file [/test/convert.bak/326/201505110030/326-m-00035] for [DFSClient_attempt_1425611626220_29142_m_000035_1001_-370311306_1] on client [192.168.7.146], because this file is already being created by [DFSClient_attempt_1425611626220_29142_m_000035_1000_-53988495_1] on [192.168.7.149] at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.recoverLeaseInternal(FSNamesystem.java:2320) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.startFileInternal(FSNamesystem.java:2083) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.startFileInt(FSNamesystem.java:2012) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.startFile(FSNamesystem.java:1963) at
https://issues.apache.org/jira/browse/MAPREDUCE-6357
Output files must in ${mapred.output.dir} 。
The design and implementation dosn't support outputing data to files out of ${mapred.output.dir}.
By looking into stack trace error, it seems that output file is already created.
If you want to write your data into multiple files, then try to generate those file name dynamically and use those files name as shown in code taken from Hadoop Definitive Guide
String basePath = String.format("%s/%s/part", parser.getStationId(), parser.getYear());
multipleOutputs.write(NullWritable.get(), value, basePath);
I hope this will help.
As it clearly suggests that the path you are trying to create,already exists. So try to do a check before creating that path whether that path exists or not.If exists, then delete that path.
FileSystem hdfs;
Path path = new Path (YourHadoopPath);
if (hdfs.exists(path)) {
hdfs.delete(path);
}

Overwriting a file that already exists in the directory during shutil.move operation

I have a Source File which I'm moving to an Archive directory using
shutil.move(srcfile, dstdir)
But when the same file already exists in the archive destination directory it throws an error saying can't move the file exists already. So I would like to overwrite the existing file. Is there a way to do that?
I had this same question. In case anyone else is looking for a solution, here's what I did.
According to the shutil documentation, there isn't a direct way to do this. However, there is an easy fix using os.remove(). Assuming that you are in the source directory and you are moving the file 'srcfile' to 'dstdir':
import shutil, os
try:
os.remove(dstdir+'srcfile')
except OSError:
pass
else:
shutil.move(srcfile, dstdir)`
This tries to clear 'dstdir' of 'srcfile' before it moves the file.

MSDOS - "The system could not find the file specified"

I am trying to copy the contents of a log file to another log file using this command:
type \\server\f$\Test path\Test.log >> \\server2\f$\Logs\Testpath\Test.log
This has always worked in the path, but recently I have changed the location (path) to Test.log. The path is slightly longer. I now get an error:
The system could not find the file specified
I have googled this statement and the common responses are: 1) check the filename exists, 2) check the filename is not corrupt 3) Check the server is online.
I have done all of this. Is there a restriction on the number of characters a path can have? If there is then is there a workaround?
UPDATE 12/07/2012 09:49 GMT
Adding quotes around the path seems to resolve the problem. Why does adding quotes resolve the problem?
The problem was that the source path had a space in it. Adding quotes around the path resolved the problem.
Type is to examine a file, not to copy.
Also, if server is an actual server and not a folder, then you should be using two slashes (\server\share)
Example:
copy \\server\f$\Sourcepath\Test.log \\server2\f$\Logs\Destpath\Test.log /y
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx?mfr=true

Resources