hostscript.js 896 B

12345678910111213141516171819202122232425262728293031323334
  1. // Thanks to Gabriel Llamas for his solution:
  2. // http://stackoverflow.com/questions/13440589/retrieve-file-attributes-from-windows-cmd
  3. /* eslint no-var: 'off' */
  4. var error = ''
  5. var fs = new ActiveXObject('Scripting.FileSystemObject')
  6. var name = WScript.Arguments.item(0)
  7. var file, json
  8. try {
  9. file = fs.GetFile(name)
  10. } catch (e) {
  11. try {
  12. file = fs.GetFolder(name)
  13. } catch (e) {
  14. error = e.message
  15. }
  16. }
  17. if (error === '') {
  18. json = '{'
  19. json += '"readonly":' + !!(file.attributes & 1) + ','
  20. json += '"hidden":' + !!(file.attributes & 2) + ','
  21. json += '"system":' + !!(file.attributes & 4) + ','
  22. json += '"directory":' + !!(file.attributes & 16) + ','
  23. json += '"archive":' + !!(file.attributes & 32) + ','
  24. json += '"symlink":' + !!(file.attributes & 1024) // Reparse point (symbolic link)
  25. json += '}'
  26. } else {
  27. json = '{"error":"' + error + '"}'
  28. }
  29. WScript.echo(json)