Thank you Bob, While you were correct adding "\\" helped, I also needed to add "\\" to the dict key so it would also pic up the root directory.
Many thanks, Glen On 26 October 2016 at 19:43, Bob Gailer <bgai...@gmail.com> wrote: > On Oct 26, 2016 2:07 PM, "Wish Dokta" <gle...@gmail.com> wrote: > > > > Hello, > > > > I am currently writing a basic program to calculate and display the size > of > > folders with a drive/directory. To do this I am storing each directory > in a > > dict as the key, with the value being the sum of the size of all files in > > that directories (but not directories). > > > > For example: > > > > { "C:\\docs" : 10, "C:\\docs123" : 200, "C:\\docs\\code\\snippets" : 5, > > "C:\\docs\\code" : 20, "C:\\docs\\pics" : 200, "C:\\docs\\code\\python" : > > 10 } > > > > Then to return the total size of a directory I am searching for a string > in > > the key: > > > > For example: > > > > for "C:\\docs\\code" in key: > > Put "\\" at the end of the search string. > > > > Which works fine and will return "C:\\docs\\code" : 20, > > "C:\\docs\\code\\snippets" : 5, "C:\\docs\\code\\python" : 10 = (35) > > > > However it fails when I try to calculate the size of a directory such as > > "C:\\docs", as it also returns "C:\\docs123". > > > > I'd be very grateful if anyone could offer any advice on how to correct > > this. > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription options: > > https://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor