Skip to Content

Move Folders containing multiple file with File adapter

Hi Experts,

I have requirement to move the folder containing multiple file from one File location to other location. The source application place 5 files into new folder (with date time stamp) every time and i need move all the files to SAP ECC.

I want to know if this is possible using File adapter standard function or custom code. I already got the other option using Unix script but i want to avoid the script if any standard way is available.

Thanks

Harish

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Oct 25, 2016 at 03:19 AM

    Hi Harish,

    How did you solve this at the end? the approach i suggested works on your case? can you update this question with final solution and close this question then it will be helpful for whoever come across this question in futere.

    Regards,

    Praveen.

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Manoj,

      The script has three functions and declaration section

      write log function

      writelog ()

      {

      time_stamp=`date +%Y/%m/%d-%H:%M:%S`

      echo "${time_stamp} $1" >> $logfile

      }

      archive function

      do_archive ()

      {

      reten_days=35

      writelog "Deleting log files older than $reten_days days." 0

      find $logdir -type f -name ${scriptnm%%.sh}"log".\* -mtime +${reten_days} -exec rm {} \;

      }

      move dir function

      move_dir ()

      {

      ls -1 $source_dir/Payment_* >/dev/null 2>&1 ||

      {

      writelog "No directories to transfer"

      return

      }

      ls -1 $source_dir | while read dirnm

      do

      [[ -d ${source_dir}/${dirnm} ]] || continue

      tmpdirnm=${dirnm%%_*}

      [[ ${tmpdirnm} = Payment ]] || continue

      writelog "Moving ${source_dir}/${dirnm} to ${dest_dir}/${dirnm}"

      echo "Moving ${source_dir}/${dirnm} to ${dest_dir}/${dirnm}"

      mv ${source_dir}/${dirnm} ${dest_dir}/${dirnm}

      retcode=$?

      if [ $retcode -eq 0 ]

      then

      writelog "Changing permissions for ${dest_dir}/${dirnm} to 775"

      chmod -R 775 ${dest_dir}/${dirnm}

      ls -1 ${dest_dir}/${dirnm} | while read file

      do

      writelog "File ${file} has been moved to ${dest_dir}/${dirnm}"

      echo "File ${file} has been moved to ${dest_dir}/${dirnm}"

      done

      else

      writelog "Move of ${source_dir}/${dirnm} to ${dest_dir}/${dirnm} has failed and needs investigating"

      fi

      done

      }

      Variable and call of function

      thishost=$( uname -n )

      scriptnm=$(basename $0)

      basedir="base dir in which all source and target exist"

      source_dir="${basedir}/file path"

      dest_dir="destination dir"

      logdir="${basedir}/log path"

      timestamp=$(date +"%Y%m%d%H%M%S")

      #support=support email address

      logfile=${logdir}/${scriptnm%%.sh}"log".${timestamp}

      move_dir

      do_archive

      exit 0

      regards,

      Harish

  • Oct 18, 2016 at 12:03 AM

    Hi Harish,

    Meaning you are trying to move the folder AND the five files at once? If so, then I think you would have to have a custom module to zip the contents of everything including the folder and then unzip on the other end. Since the folder is also technically a file (of sorts) but really without a payload I don't think you would have many options aside from the script or some type of custom adapter module to pool the contents into a .zip file on the sender side.

    Regards,

    Ryan Crosby

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 18, 2016 at 04:02 AM

    Hi Harish!

    Do you need to transfer the folder with files to target location or to pick all files from the source folder and put it to fixed predefined folder at target side?

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 18, 2016 at 07:06 AM

    Hi Harish,

    Maintain * as file name scheme in the file sender adapter then adapter will pickup the files from all the folders.

    Check below blog for more details.

    Pick Up The Files From Dynamic Directory Using Sender File Adapter

    Regards,

    Praveen.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Evgeniy Kolmakov

      Hi Evgeniy,

      Normally in PI server FTP is enabled and we can use FTP instead of NFS, actually i also tested in PI server only using FTP protocol.

      Regards,

      Praveen.