2

According to Google API doc:

https://developers.google.com/drive/api/v3/reference/files/list

orderBy: A comma-separated list of sort keys. Valid keys are 'createdTime', 'folder', 'modifiedByMeTime', 'modifiedTime', 'name', 'name_natural', 'quotaBytesUsed', 'recency', 'sharedWithMeTime', 'starred', and 'viewedByMeTime'.

Please, what is the difference between 'name' and 'name_natural'?

Thanks for your help, Bests,

pierre_j
  • 895
  • 2
  • 11
  • 26
  • Do you see any differences in the responses? – user1558604 Jul 05 '20 at 16:18
  • 1
    I proposed an answer for explaining the difference between `name_natural` and `name`. Could you please confirm it? But I'm not sure whether that is the direction you expect. So if my answer was not the direction you expect, I apologize. – Tanaike Jul 05 '20 at 22:44
  • 1
    Hello, thanks @Tanaike it sheds some light on this topic. Actually, with the names I am managing, number of digits are the same in the filename, so I would not have been able to see this difference. Thanks again! – pierre_j Jul 06 '20 at 06:37
  • Thank you for replying. I'm glad your issue was resolved. Thank you, too. – Tanaike Jul 06 '20 at 12:00

1 Answers1

3

I think that name_natural might mean the natural sort. Ref For example, it supposes that the following files are put in a folder.

enter image description here

I thought that you might be able to understand about the difference between name_natural and name from the results using these sample files with name_natural and name.

1. name_natural order:

When the file list is retrieved with the following command,

curl \
  'https://www.googleapis.com/drive/v3/files?orderBy=name_natural&q=%27%23%23%23%27%20in%20parents&fields=files(name)' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed
  • In this case, orderBy, q and fields are name_natural, '{folderId}' in parents and files(name), respectively.

The following result is retrieved.

{"files":[
    {"name":"ss1"},
    {"name":"ss01"},
    {"name":"ss02"},
    {"name":"ss03"},
    {"name":"ss04"},
    {"name":"ss05"},
    {"name":"ss06"},
    {"name":"ss07"},
    {"name":"ss08"},
    {"name":"ss09"},
    {"name":"ss10"},
    {"name":"ss11"},
    {"name":"ss12"},
    {"name":"ss100"},
    {"name":"ss1000"}
]}
  • The file of ss1 is the top of the list.
  • The files of ss100 and ss1000 are the end of the list.
  • From this result and above sample image, it seems that the default sort by name of the interface on Google Drive is name_natural.

2. name order:

When the file list is retrieved with the following command,

curl \
  'https://www.googleapis.com/drive/v3/files?orderBy=name&q=%27%23%23%23%27%20in%20parents&fields=files(name)' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed
  • In this case, orderBy, q and fields are name, '{folderId}' in parents and files(name), respectively.

The following result is retrieved.

{"files":[
    {"name":"ss01"},
    {"name":"ss02"},
    {"name":"ss03"},
    {"name":"ss04"},
    {"name":"ss05"},
    {"name":"ss06"},
    {"name":"ss07"},
    {"name":"ss08"},
    {"name":"ss09"},
    {"name":"ss1"},
    {"name":"ss10"},
    {"name":"ss100"},
    {"name":"ss1000"},
    {"name":"ss11"},
    {"name":"ss12"}
]}
  • The file of ss1 is not the top of the list.
  • The files of ss100 and ss1000 are not the end of the list.

References:

Tanaike
  • 181,128
  • 11
  • 97
  • 165