Move files in chunks of 500 from one folder to another batch

January 21, 2015 at 11:18:56
Specs: Windows 7
Hi all,

I have a requirement in windows using batch script.
I will receive some set of DAO*.xml files everyday into C:\ramesh_personal\WIN_TEMP.
If my count of files is less than 1000 then i have to copy these file from C:\ramesh_personal\WIN_SRC C:\ramesh_personal\WIN_TEMP
ELSE if count > 1000. I need to do
1)mkdir C:\ramesh_personal\WIN_500cpy
2) give full access permission to the folder
3)move first 500 files from C:\ramesh_personal\WIN_SRC to C:\ramesh_personal\WIN_500cpy folder
4)copy C:\ramesh_personal\WIN_500cpy folder\*.xml C:\ramesh_personal\WIN_TEMP
5) rm C:\ramesh_personal\WIN_500cpy\*.xml
6) remove directory C:\ramesh_personal\WIN_500cpy

This has to be done repeatedly in loop till the all the files are moved in set of 500.


I have equivalent code in unix ::

cd $PMRootDir/TgtFiles/fin/equallogics

count=`ls DAO*.xml|wc -l`
var=0
if [ $count -le 1000 ]
then
scp -2v $PMRootDir/TgtFiles/fin/equallogics/DAO*.xml dtxstap10323@dtxstbackend.us.dell.com:/dtxsttp10398/incoming/tmp

else

while [ $var -le $count ]
do
mkdir TEMP
chmod 777 TEMP
ls DAO*.xml |head -500 |xargs -i mv {} $PMRootDir/TgtFiles/fin/equallogics/TEMP
scp -2v $PMRootDir/TgtFiles/fin/equallogics/TEMP/DAO*.xml dtxstap10323@dtxstbackend.us.dell.com:/dtxsttp10398/incoming/tmp
rm -f $PMRootDir/TgtFiles/fin/equallogics/TEMP/DAO*.xml
rmdir TEMP
var=$var+500
done

fi


See More: Move files in chunks of 500 from one folder to another batch

Report •


#1
January 22, 2015 at 13:40:27
I have a requirement in windows using batch script.
I will receive some set of DAO*.xml files everyday into C:\ramesh_personal\WIN_TEMP.
If my count of files is less than 1000 then i have to copy these file from C:\ramesh_personal\WIN_SRC C:\ramesh_personal\WIN_TEMP

Wait, so you're checking to see if the file count in the target is over 1000? And why are you using a temporary directory, instead of just building a list of 500 files and moving that directly to the target?

How To Ask Questions The Smart Way


Report •

#2
January 24, 2015 at 09:36:53
Hi Razor,
Thank you for replying back. If i have confused with the naming convention , sorry for that . Let me make it simple.

1) Assume that i have a source directory C:\ramesh_personal\WIN_SRC which contains multiple XML Files. This count may be < 1000 or > 1000.

2) Now if the count is less than < 1000 , its a simple copy i do it from C:\ramesh_personal\WIN_SRC to C:\ramesh_personal\WIN_TARGET


3) Now if the count is more than 1000 , here we need to do set of things like ,
a) Create a TEMP directory ( why we need TEMP directory is , i need to store first chunk of 500 xml files in TEMP folder . From this TEMP i need to move it to C:\ramesh_personal\WIN_TARGET)

b)give full access permission to the folder C:\ramesh_personal\WIN_TEMP

c)move first 500 files from C:\ramesh_personal\WIN_SRC to C:\ramesh_personal\WIN_TEMP

d)copy C:\ramesh_personal\WIN_TEMP\*.xml to
C:\ramesh_personal\WIN_TARGET

e)Once copy is done , Delete the 500 XML FILES from C:\ramesh_personal\WIN_TEMP.

f)Remove directory C:\ramesh_personal\WIN_TEMP

g) This has to be done repeatedly in loop till the all the files are moved in set of 500



Report •
Related Solutions


Ask Question