Hi,

Just reading about a script to bulk change qgz and other files.
A couple of years ago I needed this functionality when the servernames changed, 
so I wrote this script:
####################################################
import os
import zipfile
import ntpath

# Wijzig deze map zonodig
startdir = "C:/"

newserver = "somenewserver"
oldserver = "10.195.6.122"
oldserver2 = "10.195.5.110"
oldserver3 = "10.195.5.101"

def path_leaf(path):
    head, tail = ntpath.split(path)
    return tail or ntpath.basename(head)

def replace_servername(fl, svname):
    print("opening file " + fl)
    f = open(fl,'r')
    filedata = f.read()
    f.close()
    newdata = filedata.replace(oldserver,newserver)
    data2 = newdata.replace(oldserver2,newserver)
    data = data2.replace(oldserver3,newserver)
    f = open(fl,'w')
    f.write(data)
    f.close()


def change_servername(fname, zonder_ext, ext):
    if ext == '.qlr':
        replace_servername(fname, newserver)
    if ext == '.qgz':
        with zipfile.ZipFile(fname, 'r') as zip_ref:
            zip_ref.extractall(os.path.dirname(fname))
        qgsfile = zonder_ext + '.qgs'
        qgdfile = zonder_ext + '.qgd'
        replace_servername(qgsfile, newserver)
        os.remove(fname)
        zipObj = zipfile.ZipFile(fname, 'w')
        zipObj.write(qgsfile)
        if os.path.isfile(qgdfile):
            zipObj.write(qgdfile)
            os.remove(qgdfile)
        zipObj.close()
        os.remove(qgsfile)




for (root, dirs, files) in os.walk(startdir, topdown=True):
    if files:
        for f in files:
            fl = os.path.join(root,  f)
            zonder, extension = os.path.splitext(fl)
            if extension == '.qgz' or extension == '.qlr':
                change_servername(fl, zonder, extension)

print("klaar")


##############################################################



Reginald Carlier
Deskundige GIS
Gemeente Ingelmunster, Oostrozebekestraat 4, 8770 Ingelmunster
T+32 51 33 74 39www.ingelmunster.be
0207.485.473 (gemeente) - 0212.221.845 (OCMW)
​RPR Rechtbank van eerste aanleg West-Vlaanderen afdeling Kortrijk

Wij werken enkel op afspraak
Schrijf je in op onze nieuwsbrief!
Raadpleeg onze disclaimer
-----Oorspronkelijk bericht-----
Van: QGIS-User <[email protected]> Namens 
[email protected]
Verzonden: vrijdag 5 april 2024 9:58
Aan: [email protected]
Onderwerp: QGIS-User Digest, Vol 218, Issue 10

Send QGIS-User mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.osgeo.org/mailman/listinfo/qgis-user
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific than "Re: 
Contents of QGIS-User digest..."


Today's Topics:

   1. Re: Moving many project files - bulk updating paths to
      tables? (Tony Shepherd (FarmMaps NZ))
   2. Re: Announce - migrate our mailing lists to Discourse
      (DancesWithCars)
   3. Re: Announce - migrate our mailing lists to Discourse
      (Michael Shand)
   4. Re: Announce - migrate our mailing lists to Discourse
      (David Strip)
   5. Re: Moving many project files - bulk updating paths to
      tables? (Gordon Wakelin-King)


----------------------------------------------------------------------

Message: 1
Date: Fri, 5 Apr 2024 08:06:48 +1300
From: "Tony Shepherd \(FarmMaps NZ\)" <[email protected]>
To: "'Jorge Gustavo Rocha'" <[email protected]>,
        <[email protected]>
Subject: Re: [Qgis-user] Moving many project files - bulk updating
        paths to tables?
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

Thanks Jorge



Yes, I toyed with that, but somewhat painful with thousands to process.



Has anybody scripted or coded something for this?



Cheers



From: QGIS-User <[email protected]> On Behalf Of Jorge Gustavo 
Rocha via QGIS-User
Sent: Friday, April 5, 2024 7:53 AM
To: [email protected]
Subject: Re: [Qgis-user] Moving many project files - bulk updating paths to 
tables?



Hi Tony,

You can unzip the qgz file and change the text in the qgs files. qgs are text 
files. Afterwards, you can create the zip again with the qgz extension or open 
the qgs file directly.

I hope it helps,

Jorge

On 04/04/24 19:28, Tony Shepherd (FarmMaps NZ) via QGIS-User wrote:

Hi All



I am sure I am not the first to ponder how to deal with this.  I have loads, 
thousands likely, of project files in a series of folders and subfolders.  I 
need to move those files and folders to a new location to enable other staff to 
use the project files and their associated shp files, geo packages, rasters etc.



Essentially, I am shifting my entire collection of GIS work to a shared 
location for others to start using, so moving from a sole operator to a shared 
environment.



In my old MapInfo days, I would simply do a bulk search and replace over the 
workspace files (text-based so this is easy) and change the paths that need 
changing and all would be ok.



As qgz files are not easily modified through a text editor, are there any tools 
out there to enable bulk changing of file paths in those files?



Any other approaches?



Cheers

Tony



------------------------------------------------------------------------------------------------------------------

Tony Shepherd

  GeoSpatial Manager @ FarmMaps NZ & Photographer @ Shepherd Photos



Phone ? 027 435 6193  | Website ?  <http://shepherdphotos.co.nz/> 
shepherdphotos.co.nz

Email ? Maps  <mailto:[email protected]> [email protected]  |  Email ? Photos   
<mailto:[email protected]> [email protected]

Facebook  <https://www.facebook.com/TonyShepherdPhotos> TonyShepherdPhotos













_______________________________________________
QGIS-User mailing list
[email protected] <mailto:[email protected]>
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://lists.osgeo.org/pipermail/qgis-user/attachments/20240405/e1ecbd4f/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 3062 bytes
Desc: not available
URL: 
<http://lists.osgeo.org/pipermail/qgis-user/attachments/20240405/e1ecbd4f/attachment-0001.jpg>

------------------------------

Message: 2
Date: Thu, 4 Apr 2024 16:17:38 -0400
From: DancesWithCars <[email protected]>
To: chris hermansen <[email protected]>
Cc: R?gis Haubourg <[email protected]>, qgis-psc
        <[email protected]>, [email protected],
        [email protected]
Subject: Re: [Qgis-user] Announce - migrate our mailing lists to
        Discourse
Message-ID:
        <CA+zqz3V2B-pciLiog2H=RpaWJ7yeWqmQooFJ=gFUK9POsQ=b...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I won't be making the transition.
Bye


On Thu, Apr 4, 2024, 14:06 chris hermansen via QGIS-User < 
[email protected]> wrote:

> R?gis and everyone else,
>
> My apologies; I try not to top post but my response is more an overall
> reaction to your announcement rather than a point by point response.
>
> I was a member (??) over at opensource.com's Discourse instance until
> RedHat decided to shut down support for opensource.com, so I have some
> experience with that Discourse configuration, also plenty of
> experience with mailing lists.  Also familiarity with the Ubuntu
> Forums, Stack Exchange etc.
>
> In my experience, Discourse "out of the box" doesn't offer any net
> benefit to its users.
>
> It's quite possible that people interested in, and willing to invest
> time and effort into customizing their usage profile would benefit
> more from Discourse than from a mailing list.  I have no experience with that.
>
> You may be correct when you say that we will attract more new users by
> offering them Discourse than by maintaining a mailing list.  I guess
> the question that begs to be asked is, will those new users thereby
> turn into contributors, or will the biggest Discourse channel be "how
> do I install QGIS on my new Mac"?
>
> I suppose, perhaps wrongly, that most of us on this (and other)
> mailing lists are here because the list provides a sense of community,
> an opportunity to pay back by offering a bit of help, an opportunity
> to stumble on something new and useful from time to time... what else?
> I'm pretty sure none of us participate in this list to learn how to
> participate effectively in lists.  Moreover, we don't really have the
> tools to "only pay attention to topics X, Y and Z".  So all of us get
> to see the beginner questions, and the responses, and sometimes we
> find ourselves in the situation of starting fresh with something that,
> because of this broad familiarity, is not a total blank.
>
> In contrast, in my experience, moving to Discourse, or any other
> similar forum-type structure, allows or even encourages us to stick to
> certain topics that we think may be of interest and avoid all others.
>
> I would argue that we thereby cheapen and diminish our contribution
> back to the forum, simply because we miss real opportunities to help
> while we avoid reading certain topics; and by doing so, we reduce the
> sense of community we get by belonging to the list.  I would further
> argue that we run the risk of not learning many new things because by
> streaming topics into tens or hundreds of specialist channels, we
> inevitably miss things that might benefit us.
>
> Finally, we have the "opportunity" to spend more of our limited time
> learning about configuring our participation in this mechanism, rather
> than just participating.  Your example of learning how to treat
> Discourse like a mailing list by following the Mozilla tutorial
> addresses this situation precisely - instead of helping a person with
> their configuration issues, or learning more about how to structure
> the queries used in QGIS, we are tweaking the Discourse knobs and levers to 
> get the "optimum" experience.
>
> I guess you can tell that I'm negative on this concept.  I don't feel
> that the mailing list is a be-all and end-all.  But I am pretty sure,
> again based on my experience, that the lovely community we have here
> on [email protected] will not be the same collection of good
> things once migrated to Discourse.  I do hope that I am wrong!
>
> On Wed, Apr 3, 2024 at 7:04?AM R?gis Haubourg via QGIS-User <
> [email protected]> wrote:
>
>> [Message sent to all QGIS's lists. Sorry for crossposting - **please
>> reply only in PSC list**  ] [stuff deleted]
>>
>>
>> Any thought from you is more than welcome, from ranting against
>> modernity to thanking SAC for their hard work.
>>
>  And thank you, SAC, for your hard work!
>
> --
> Chris Hermansen ? clhermansen "at" gmail "dot" com
>
> C'est ma fa?on de parler.
> _______________________________________________
> QGIS-User mailing list
> [email protected]
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://lists.osgeo.org/pipermail/qgis-user/attachments/20240404/ffe5634d/attachment-0001.htm>

------------------------------

Message: 3
Date: Thu, 4 Apr 2024 20:49:03 +0000
From: Michael Shand <[email protected]>
To: "[email protected]" <[email protected]>
Subject: Re: [Qgis-user] Announce - migrate our mailing lists to
        Discourse
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

Another great mapping list bites the dust.
I used CartoSOC for over 20 years which was great for info and connecting with 
like minded cartographers, after a merger it became a Forum and died a slow 
death.

Sent from Samsung mobile

On 4 Apr 2024 21:29, DancesWithCars via QGIS-User <[email protected]> 
wrote:
I won't be making the transition.
Bye


On Thu, Apr 4, 2024, 14:06 chris hermansen via QGIS-User 
<[email protected]<mailto:[email protected]>> wrote:
R?gis and everyone else,

My apologies; I try not to top post but my response is more an overall reaction 
to your announcement rather than a point by point response.

I was a member (??) over at opensource.com<http://opensource.com/>'s Discourse 
instance until RedHat decided to shut down support for 
opensource.com<http://opensource.com/>, so I have some experience with that 
Discourse configuration, also plenty of experience with mailing lists.  Also 
familiarity with the Ubuntu Forums, Stack Exchange etc.

In my experience, Discourse "out of the box" doesn't offer any net benefit to 
its users.

It's quite possible that people interested in, and willing to invest time and 
effort into customizing their usage profile would benefit more from Discourse 
than from a mailing list.  I have no experience with that.

You may be correct when you say that we will attract more new users by offering 
them Discourse than by maintaining a mailing list.  I guess the question that 
begs to be asked is, will those new users thereby turn into contributors, or 
will the biggest Discourse channel be "how do I install QGIS on my new Mac"?

I suppose, perhaps wrongly, that most of us on this (and other) mailing lists 
are here because the list provides a sense of community, an opportunity to pay 
back by offering a bit of help, an opportunity to stumble on something new and 
useful from time to time... what else?  I'm pretty sure none of us participate 
in this list to learn how to participate effectively in lists.  Moreover, we 
don't really have the tools to "only pay attention to topics X, Y and Z".  So 
all of us get to see the beginner questions, and the responses, and sometimes 
we find ourselves in the situation of starting fresh with something that, 
because of this broad familiarity, is not a total blank.

In contrast, in my experience, moving to Discourse, or any other similar 
forum-type structure, allows or even encourages us to stick to certain topics 
that we think may be of interest and avoid all others.

I would argue that we thereby cheapen and diminish our contribution back to the 
forum, simply because we miss real opportunities to help while we avoid reading 
certain topics; and by doing so, we reduce the sense of community we get by 
belonging to the list.  I would further argue that we run the risk of not 
learning many new things because by streaming topics into tens or hundreds of 
specialist channels, we inevitably miss things that might benefit us.

Finally, we have the "opportunity" to spend more of our limited time learning 
about configuring our participation in this mechanism, rather than just 
participating.  Your example of learning how to treat Discourse like a mailing 
list by following the Mozilla tutorial addresses this situation precisely - 
instead of helping a person with their configuration issues, or learning more 
about how to structure the queries used in QGIS, we are tweaking the Discourse 
knobs and levers to get the "optimum" experience.

I guess you can tell that I'm negative on this concept.  I don't feel that the 
mailing list is a be-all and end-all.  But I am pretty sure, again based on my 
experience, that the lovely community we have here on 
[email protected]<mailto:[email protected]> will not be the 
same collection of good things once migrated to Discourse.  I do hope that I am 
wrong!

On Wed, Apr 3, 2024 at 7:04?AM R?gis Haubourg via QGIS-User 
<[email protected]<mailto:[email protected]>> wrote:

[Message sent to all QGIS's lists. Sorry for crossposting - **please reply only 
in PSC list**  ]

[stuff deleted]


Any thought from you is more than welcome, from ranting against modernity to 
thanking SAC for their hard work.

 And thank you, SAC, for your hard work!

--

Chris Hermansen ? clhermansen "at" gmail "dot" com

C'est ma fa?on de parler.
_______________________________________________
QGIS-User mailing list
[email protected]<mailto:[email protected]>
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://lists.osgeo.org/pipermail/qgis-user/attachments/20240404/c24a2f82/attachment-0001.htm>

------------------------------

Message: 4
Date: Thu, 4 Apr 2024 15:29:24 -0600
From: David Strip <[email protected]>
To: "[email protected]" <[email protected]>
Subject: Re: [Qgis-user] Announce - migrate our mailing lists to
        Discourse
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

An HTML attachment was scrubbed...
URL: 
<http://lists.osgeo.org/pipermail/qgis-user/attachments/20240404/019a55df/attachment-0001.htm>

------------------------------

Message: 5
Date: Fri, 5 Apr 2024 07:58:23 +0000
From: Gordon Wakelin-King <[email protected]>
To: "Tony Shepherd (FarmMaps NZ)" <[email protected]>, 'Jorge Gustavo
        Rocha' <[email protected]>, "[email protected]"
        <[email protected]>
Subject: Re: [Qgis-user] Moving many project files - bulk updating
        paths to tables?
Message-ID:
        
<me2p282mb22422efef0bec9774041f914e4...@me2p282mb2242.ausp282.prod.outlook.com>

Content-Type: text/plain; charset="windows-1252"

There is a project packager plugin that works pretty well. It may not be 
exactly what you need but maybe the author could be approached for tips on the 
process.

Get Outlook for Android<https://aka.ms/AAb9ysg> ________________________________
From: QGIS-User <[email protected]> on behalf of Tony Shepherd 
(FarmMaps NZ) via QGIS-User <[email protected]>
Sent: Friday, April 5, 2024 6:06:48 AM
To: 'Jorge Gustavo Rocha' <[email protected]>; [email protected] 
<[email protected]>
Subject: Re: [Qgis-user] Moving many project files - bulk updating paths to 
tables?


Thanks Jorge



Yes, I toyed with that, but somewhat painful with thousands to process.



Has anybody scripted or coded something for this?



Cheers



From: QGIS-User <[email protected]> On Behalf Of Jorge Gustavo 
Rocha via QGIS-User
Sent: Friday, April 5, 2024 7:53 AM
To: [email protected]
Subject: Re: [Qgis-user] Moving many project files - bulk updating paths to 
tables?



Hi Tony,

You can unzip the qgz file and change the text in the qgs files. qgs are text 
files. Afterwards, you can create the zip again with the qgz extension or open 
the qgs file directly.

I hope it helps,

Jorge

On 04/04/24 19:28, Tony Shepherd (FarmMaps NZ) via QGIS-User wrote:

Hi All



I am sure I am not the first to ponder how to deal with this.  I have loads, 
thousands likely, of project files in a series of folders and subfolders.  I 
need to move those files and folders to a new location to enable other staff to 
use the project files and their associated shp files, geo packages, rasters etc.



Essentially, I am shifting my entire collection of GIS work to a shared 
location for others to start using, so moving from a sole operator to a shared 
environment.



In my old MapInfo days, I would simply do a bulk search and replace over the 
workspace files (text-based so this is easy) and change the paths that need 
changing and all would be ok.



As qgz files are not easily modified through a text editor, are there any tools 
out there to enable bulk changing of file paths in those files?



Any other approaches?



Cheers

Tony



------------------------------------------------------------------------------------------------------------------

Tony Shepherd

  GeoSpatial Manager @ FarmMaps NZ & Photographer @ Shepherd Photos



Phone ? 027 435 6193  | Website ? 
shepherdphotos.co.nz<http://shepherdphotos.co.nz/>

Email ? Maps [email protected]<mailto:[email protected]>  |  Email ? Photos  
[email protected]<mailto:[email protected]>

Facebook TonyShepherdPhotos<https://www.facebook.com/TonyShepherdPhotos>





[FM_logo1_small (Custom)]





_______________________________________________

QGIS-User mailing list

[email protected]<mailto:[email protected]>

List info: https://lists.osgeo.org/mailman/listinfo/qgis-user

Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://lists.osgeo.org/pipermail/qgis-user/attachments/20240405/94be66d9/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 3062 bytes
Desc: image001.jpg
URL: 
<http://lists.osgeo.org/pipermail/qgis-user/attachments/20240405/94be66d9/attachment.jpg>

------------------------------

Subject: Digest Footer

_______________________________________________
QGIS-User mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


------------------------------

End of QGIS-User Digest, Vol 218, Issue 10
******************************************
_______________________________________________
QGIS-User mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to