on 10-17-2016 11:16 PM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Praveen,
Thanks for your input, unfortunately my scenario is with NFS and i used the Unix script to achieve this. The pseudocode is
move_dir ()
{
ls -1 $source_dir/Start_* >/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} = Start ]] || 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
}
The Variables needs to be defined as
basedir
source_dir
dest_dir
logdir
regards,
Harish
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Evgeniy,
I just tested again, i have placed these two directories in the source directory which PI is polling for.
And these two folders are placed successfully in the target directory including the files.
I also mentioned all the screen shots in the blog which i tested in my system.
What is your operating system which you are placing the files? are you testing NFS or FTP?
Regards,
Praveen.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pushkar,
In ITK for Download Task the parameter DownloadDir is a mandatory field you can't leave it empty. ITK does create a subfolder dynamically with filePrefix paramater with appending Timestamp, inside which there would be number of CSV file depending on the event you are running. There is no way in ITK you can avoid this that's the standard behaviour of ITK.
Br,
Manoj
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Harish!
I guess you're right. Either custom OS script for copying files (without PI involved) or custom module for picking files from dynamically created folders.
Regards, Evgeniy.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.