Select to view content in your preferred language

Script to Change Drive Letter

3875
1
04-14-2015 03:37 PM
EricBregant
New Contributor

Hey everyone, I was recently informed that my company's IT dept. wants to change the drive letter that all of our GIS files are stored on. We have thousands of .mxds, layer files and .shp files stored on the drive. I have very minor code writing experience so I was looking for some help.

Our GIS folder is on the H: drive and we have folders for each client with a "project" sub-folder that contains all the .mxds  a "shapefile" folder that contains all the .shp files an "images" folder and "tables" folder. I attached some images to show the basic structure!

The drive letter that my company wants to switch to is F:

I have started to mess around with the following python script I found on here.

import os

     for dirname, dirnames, filenames in os.walk(r"H:\GIS Something something something"):

          for filename in filenames:

          path = os.path.join(dirname, filename)

          basename, extension = os.path.splitext(path)

          if extension == ".mxd":

               mxd = arcpy.mapping.MapDocument(path)

               mxd.findAndReplaceWorkspacePaths(r"H:", r"F:")

               mxd.save()

               del mxd

I know I am missing chunks of code that deal with the shapefile, image and table folders. Just not sure where to put all that stuff.

Thanks to anyone that can help me out!

-Eric

0 Kudos
1 Reply
NeilAyres
MVP Alum

You are on the right track there with "findAndReplace...."

As you have probably seen the examples here :

http://resources.arcgis.com/en/help/main/10.2/index.html#/Updating_and_fixing_data_sources_with_arcp...

But for the future you should maybe consider using relative pathnames from the mxd to the data.

Found in the map doc properties page.

MapDocProperties_RelativePaths.jpg