I have a table with field which contains path to database. The same thing in this field will be the extension of file. Here is how it looks like
D:\Проекты\Москва для тестов\Test.gdb\graf_fd
I need to have this
D:\Проекты\Москва для тестов\Test.gdb\
Probably I should replace everything after 'gdb\'. I know that I can type something like delete last 7 charachters, but the name of dataset can be another in other databases as well as the length of string data before 'gdb\'. So are there codes for removing or replacing the characters after certain word?
-
Even though you have a file geodatabase in your pathname, your pathname is simply a string, so the answer to this is pure Python (best researched at Stack Overflow) rather than ArcPy (best researched here at Geographic Information Systems).PolyGeo– PolyGeo ♦2016年08月17日 07:37:31 +00:00Commented Aug 17, 2016 at 7:37
-
@PolyGeo, I believe Pavel wants to achieve this using ArcMap and field calculator even though you would need pure Python to split a string. Sounds like a GIS.SE question to me :) Please open it up so I could post an answer :)Alex Tereshenkov– Alex Tereshenkov2016年08月17日 07:40:22 +00:00Commented Aug 17, 2016 at 7:40
-
@AlexTereshenkov вы правы)Pavel Pereverzev– Pavel Pereverzev2016年08月17日 07:42:51 +00:00Commented Aug 17, 2016 at 7:42
-
@AlexTereshenkov I've re-opened it but I do think this is one that falls on the Stack Overflow side of the Python/ArcPy line. To help ArcPy users become more proficient in Python I think we should always remind them of the enormous Python resource that is Stack Overflow.PolyGeo– PolyGeo ♦2016年08月17日 07:42:53 +00:00Commented Aug 17, 2016 at 7:42
-
@PolyGeo, I hear you, chief. Agreed.Alex Tereshenkov– Alex Tereshenkov2016年08月17日 07:55:36 +00:00Commented Aug 17, 2016 at 7:55
1 Answer 1
Provided you have two fields in the feature class, LongPath
and ShortPath
. Both are of Text
type.
To calculate the ShortPath
field, right-click the field name in the attribute table and choose Field Calculator
, switch to Python
parser and run:
'\\'.join(!LongPath!.split('\\')[:-1])
This will construct a string path with all parts except the last one.
LongPath ShortPath
D:\Проекты\Москва для тестов\Test.gdb\graf_fd D:\Проекты\Москва для тестов\Test.gdb
D:\Проекты\Москва для тестов\Test.gdb\graf_fd D:\Проекты\Москва для тестов\Test.gdb
More readings on Python used here:
-
that works! Thank you so much! I defiftely should get some knowledge about Python :)Pavel Pereverzev– Pavel Pereverzev2016年08月17日 08:19:22 +00:00Commented Aug 17, 2016 at 8:19
-
@PavelPereverzev, no problem at all. Yeah, Python can be very handy. Check this post out with the resources to learn compiled, great one - gis.stackexchange.com/questions/53816/…Alex Tereshenkov– Alex Tereshenkov2016年08月17日 08:23:14 +00:00Commented Aug 17, 2016 at 8:23
Explore related questions
See similar questions with these tags.