0

I wanted to take paths to directories from files that we got from a user as parameters of function and from files extract the paths and move all files and folders in the source directory to the destination directory, but something went wrong: It writes to me, that "No such file or directory"

With this input

enter image description here

Where dest_adr.txt contains this path: C:\Users\Michal\Desktop\tmp and source_adr.txt contains this path: C:\Users\Michal\Desktop\test\

#!/bin/bash

FILE_WITH_ADRESS_TO_BLENDER_PATH=$1
FILE_WITH_ADRESS_TO_FOLDER_WITH_ADDONS=$2

function move_folders(){    
    mv "${PATH_TO_FOLDER_WITH_ADDONS_}"/* "${PATH_TO_BLENDR_DIRECTORIE_}"/
}   

if [  $# -eq 0 ]
  then
      PATH_TO_BLENDR_DIRECTORIE="C:/Program Files/Blender Foundation/Blender 3.0/3.0/scripts/addons"
      FOLDER_WITH_ADDONS="none"
      echo $PATH_TO_BLENDR_DIRECTORIE
      echo $FOLDER_WITH_ADDONS
  else  
      PATH_TO_BLENDR_DIRECTORIE_=$(cat $FILE_WITH_ADRESS_TO_BLENDER_PATH | sed -e 's/\\/\//g' -e 's/\C://g')
      PATH_TO_FOLDER_WITH_ADDONS_=$(cat $FILE_WITH_ADRESS_TO_FOLDER_WITH_ADDONS | sed -e 's/\\/\//g' -e 's/\C://g')
      echo $PATH_TO_BLENDR_DIRECTORIE_
      echo $PATH_TO_FOLDER_WITH_ADDONS_
      move_folders
  fi
5
  • Did you checked that test/ has still files, if you ran the script, they will be all already moved to your destination Commented Apr 28, 2022 at 12:23
  • Please don't post images of text. Just place the text itself in your question, formatted as a code sample. Commented Apr 28, 2022 at 12:29
  • Please don't post images of text. Just place the text itself in your question, formatted as a code sample. Commented Apr 28, 2022 at 12:30
  • 1
    "folders" and "directories" are different things. Everything you are talking about here is a directory. The word "folder" has no place anywhere in this question. Commented Apr 28, 2022 at 12:41
  • Folders are also called "directories," and they are created on the hard drive (HD) or solid-state drive (SSD) when the operating system and applications are installed. Files are always stored in folders Commented Apr 28, 2022 at 14:43

2 Answers 2

0

Use Shell Parameter Expansion

adrian@pc:/tmp/move> path_to_file=/usr/share/man/man1/bash.1.gz
adrian@pc:/tmp/move> folder_path=${path_to_file%/*} 
adrian@pc:/tmp/move> echo $folder_path 
/usr/share/man/man1
adrian@pc:/tmp/move> file_name=${path_to_file##*/}
adrian@pc:/tmp/move> echo $file_name 
bash.1.gz

Don't use cat to send variable, it will send content of file no path, use echo or printf instead.

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

Comments

-2

The error occurs because the test/ directory is empty.

Try again with files within it. It's expected behavior to fail with a wildcard if you don't have files in the source directory you are trying to move.

Edit: Or use mv -r

3 Comments

The directory has a few folders inside from the very beginning :(
Well use move with -r to recurse over your folders
output of tree of the test/ folder ?

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.