× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



John,

I'm going to take a closer look at Python, but I need to know how it runs.
This will be called as part of a larger process within AJS.
Also, there 4 links for download, which one should I be selecting?

Paul

-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of John Yeung
Sent: Monday, May 05, 2014 6:46 PM
To: Midrange Systems Technical Discussion
Subject: Re: Need to move all objects from lib A to lib B in batch mode with a replace option if the object already exists

On Mon, May 5, 2014 at 5:44 PM, Steinmetz, Paul <PSteinmetz@xxxxxxxxxx> wrote:
I'm looking for a solution to move all objects from lib A to lib B in
batch mode with a replace option if the object already exists.

Well, I'm sure there are several ways to do this, but as I'm the resident Python fanboy, I will present a simple three-line Python
script:

# begin script
import os
for name in os.listdir('/qsys.lib/libA.lib'):
os.rename('/qsys.lib/libA.lib/' + name, '/qsys.lib/libB.lib/' + name) # end script

In this case, it's so short because the behavior of os.rename is to automatically replace (assuming you have the necessary authority).

If you had wanted to only move objects that DON'T exist in lib B:

# begin script
import os
objectsB = os.listdir('/qsys.lib/libB.lib') for name in os.listdir('/qsys.lib/libA.lib'):
if name not in objectsB:
os.rename('/qsys.lib/libA.lib/' + name, '/qsys.lib/libB.lib/' + name) # end script

(The objectsB variable isn't strictly necessary, but getting the list of objects once up front is more efficient than recalculating the list every time within the loop, especially if there are lots of objects in lib B.)

Finally, if you had wanted only newer objects to replace older ones:

# begin script
import os
libA = '/qsys.lib/libA.lib'
libB = '/qsys.lib/libB.lib'
objectsB = os.listdir(libB)
for name in os.listdir(libA):
mtimeA = os.path.getmtime(libA + '/' + name)
if name in objectsB:
mtimeB = os.path.getmtime(libB + '/' + name)
else:
mtimeB = 0
if mtimeA > mtimeB:
os.rename(libA + '/' + name, libB + '/' + name) # end script

All these can be done on the i with iSeriesPython (www.iseriespython.com), which is freely downloadable and open source.
And simple enough to install on the i that even I was able do it in just a few minutes.

John Y.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.