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. Apr 7, 2017 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, 2017 at 16:38

1 Answer 1

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, 2017 at 7:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .