Advertisement
mgis90

INI_Sort.ahk

May 2nd, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;INI_sort.ahk                                   by Mgis     2016-05-02
  2. ;very special purpose of sorting ini files, with proper regarding of sections, now also sorted
  3. ;param1 - ini file to sort
  4. #SingleInstance force
  5. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  6. #LTrim  ; Allows continuation sections to be indented. Positional. May be turned off via #LTrim Off
  7. #KeyHistory 0  ; Disable keyboard and mouse event history.
  8. #Warn
  9. file=
  10. newfile=
  11. sections=
  12. var=
  13. ;SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  14. CoordMode,ToolTip,Screen
  15.  
  16.  
  17. ;-----brak parametrów wyjdź
  18. if 0<1
  19. {
  20.     MsgBox,16,Oh noes,No parameters were given!
  21.     ExitApp
  22. }
  23. ToolTip,params received`n%1%,600,30
  24.  
  25.  
  26. ;-----czy plik istnieje
  27. file=%1%
  28. if not FileExist(file)
  29. {
  30.     MsgBox,48,Yikes,File not found!
  31.     ExitApp
  32. } else
  33.     MsgBox,64,Yeah,File found!,1
  34.  
  35.  
  36. ;-----zamień na długą nazwę
  37. Loop %file%, 1
  38.     file = %A_LoopFileLongPath%
  39. ToolTip,long path is:`n%file%,600,60,2
  40.  
  41.  
  42. ;-----ustal ścieżkę nowego bratniego pliku
  43. StringTrimRight,newfile,file,4
  44. newfile.="_new.ini"
  45.  
  46.  
  47. ;-----wczytaj listę sekcji     (sortuj bo będą podane w znalezionej)
  48. IniRead,sections,%file%
  49. Sort, sections
  50.  
  51.  
  52. ;-----dla każdej z sekcji
  53. ;now we have them separated by linefeed, we can parse them by loop parse
  54. Loop,parse, sections, `n, `r
  55. {
  56.     IniRead,var,%file%,%A_LoopField%
  57.     ;-----mamy całą sekcję w var
  58.     Sort, var
  59.     IniWrite, %var%, %newfile%, %A_LoopField%
  60.     ToolTip,section:`n%A_LoopField%,600,90,3
  61.     Sleep 100
  62. }
  63. MsgBox,64,Done,Done,1
  64. return  ;autoexec
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement