I have to copy some files and I have a field where I write the destination path. But if I do not write "/" at the end, it takes the last word and creates a file with that name. How can treat everything as directory?

Example :


In that way, it creates file with name folder2 in directory folder1.

  • 1
    Try adding a / at the end of the name. – Stephen Rauch Apr 7 '17 at 16:33
  • Yes, but if the user do not write at the end it should treat it also as directory. How to implement that ? cp -r ${Path1} ${Path2} – Божидар Маринов Apr 7 '17 at 16:38
cp -r -t target inputs

Will ensure that target shall be taken to be as a directory. GNU cp is needed.

  • I did not find any command that can fix my problem, so i use this : if [ ! -d {$Path} ]; then mkdir -p ${PATH} fi – Божидар Маринов Apr 10 '17 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.