findpath.awk 649 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. BEGIN {
  2. strVariable = ""
  3. strPath = ""
  4. if (ARGC != 2)
  5. {
  6. printf("Usage: dir /s <file> | awk -f findpath.awk <variable name>\n");
  7. } else
  8. {
  9. strVariable = ARGV[1];
  10. ARGC = 1;
  11. }
  12. }
  13. /Directory/ {
  14. fSpace = 0;
  15. strTemp = $3;
  16. for(dwIndex = 4; dwIndex <= NF; dwIndex++)
  17. {
  18. strTemp = strTemp " " $(dwIndex)
  19. fSpace = 1;
  20. }
  21. if (1 == fSpace)
  22. {
  23. strPath = "\"" strTemp "\"";
  24. } else
  25. strPath = strTemp;
  26. }
  27. END {
  28. if ((length(strVariable) > 0) && (length(strPath) > 0))
  29. printf("set %s=%s\n", strVariable, strPath);
  30. }