how to set 'arrange by' for all the folders in the finder
To answer your first question, this isn't a script, but it is a procedure you can follow to make all Finder windows sorted by name. Open a Finder window. Select a regular folder; not a pseudo-folder (the Use as defaults button does not appear on Airdrop or Recents). Press Command-J. In the Sort By drop-down control, select Name. Click the Use as defaults button at the bottom of the window.

For the second, no, "sort by" sorts everything, including folders. If there are particular files or folders you want at the top of the list, you could start their name with a space, but don't do that to folders that applications or the system expect to have particular names. It does work for folders you create within your own Documents directory, however.