Jump to content
Sign in to follow this  
niteshade

Read Path From INI File

Recommended Posts

niteshade

Trying to read a path from an INI file. However, I think it reads the value and places it in a string container-thingie i.e. between "", which doesn't let the rest of it work. I'll show you the code.

Global $Backups = @WorkingDir & "\Backups"
Global $Plugins = @WorkingDir & "\Plugins"
Global $Temp = @WorkingDir & "\Temp"
Global $Tools = @WorkingDir & "\Tools"

;READ PLUGIN DIRECTORY
$AppName = IniRead($Plugins & "\MP3TAG.LB","Data","Name","App")
$Path = IniRead($Plugins & "\MP3TAG.LB","Data","Path","LOL")
MsgBox(0,"",$AppName)
MsgBox(0,"",$Path)

ToLocal($Path)
$Date = GetDate()
CompressFile($Date,$AppName)
Cleanup()
MsgBox(0,"","Completed")

;FUNCTION - COPY TO LOCAL DIRECTORY
Func ToLocal($Dir)
    FileDelete($Temp & "\*.*")
    DirCopy($Dir,$Temp,1)
EndFunc

;FUNCTION - GET AND FORMAT DATE
Func GetDate()
    $UnformattedDate = _DateTimeFormat( _NowCalc(),1)
    $FormattedDate = StringReplace($UnformattedDate," ","-")
    Return $FormattedDate
EndFunc

;FUNCTION - COMPRESS FILE
Func CompressFile($FDate,$APP)
    Run(@ComSpec & " /c " & "7z.exe a -y " & $Backups & "\" & $APP & "_" & $FDate & ".7z " & $Temp & "\*", $Tools, @SW_HIDE)
EndFunc

;FUNCTION - CLEAR TEMP DIRECTORY
Func Cleanup()
    DirRemove($Temp & "\",1)
    DirCreate($Temp)
EndFunc

The contents of the INI file are as follows:

[Data]
Name = MP3Tag
Path = @UserProfileDir & "\AppData\Roaming\Mp3tag"

Share this post


Link to post
Share on other sites
SmOke_N

You're using a macro in the return string. You kind of need to define it first.

See if this helps:

$Path = '"' & _ConvertMacroFromString(IniRead($Plugins & "\MP3TAG.LB","Data","Path","LOL")) & '"'


Func _ConvertMacroFromString($s_str); Cheap version, think I wrote an elaborate one once
    Local $a_macros = StringRegExp($s_str, "(\@\w+)", 3)
    If @error Then Return SetError(1, 0, $s_str)
    Local $s_macro, $s_escape = "(\.|\||\*|\?|\+|\(|\)|\{|\}|\[|\]|\^|\$|\\)"
    For $i = 0 To UBound($a_macros) - 1
        $s_macro = Execute($a_macros[$i])
        If @error Or $s_macro = "" Then ContinueLoop
        $s_macro = StringRegExpReplace($s_macro, $s_escape, "\\$1")
        $s_str = StringRegExpReplace($s_str, _
            "(\A|\W)(" & $a_macros[$i] & ")(\W|\z)", _
            "$1" & $s_macro & "$3")
    Next
    Return $s_str
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
SmOke_N

Knew I had done something else like this:

http://www.autoitscript.com/forum/index.ph...st&p=528667


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
niteshade

I've retried it, and changed some stuff in the INI file too. The path is returned correctly, but it still doesn't work

#include <Array.au3>
#include <Date.au3>
#include <File.au3>
#include <Constants.au3>

Global $Backups = @WorkingDir & "\Backups"
Global $Plugins = @WorkingDir & "\Plugins"
Global $Temp = @WorkingDir & "\Temp"
Global $Tools = @WorkingDir & "\Tools"

;READ PLUGIN DIRECTORY
$AppName = IniRead($Plugins & "\MP3TAG.LB","Data","Name","App")
$Path = '"' & _ConvertMacroFromString(IniRead($Plugins & "\MP3TAG.LB","Data","Path","LOL")) & '"'

MsgBox(0,"",$AppName)
MsgBox(0,"",$Path)

ToLocal($Path)
MsgBox(0,"","Copied")
$Date = GetDate()
CompressFile($Date,$AppName)
Cleanup()
MsgBox(0,"","Completed")
MsgBox(0,"",RegRead("HKEY_LOCAL_MACHINE\Software\CCleaner","UpdateCheck"))

;FUNCTION - COPY TO LOCAL DIRECTORY
Func ToLocal($Dir)
    FileDelete($Temp & "\*.*")
    DirCopy($Dir,$Temp,1)
EndFunc

;FUNCTION - RETRIEVE REGISTRY KEYS
Func RegRetrieve($REGPATH,$REGNAME)
    $REGVALUE = RegRead($REGPATH,$REGNAME)
    
EndFunc

;FUNCTION - GET AND FORMAT DATE
Func GetDate()
    $UnformattedDate = _DateTimeFormat( _NowCalc(),1)
    $FormattedDate = StringReplace($UnformattedDate," ","-")
    Return $FormattedDate
EndFunc

;FUNCTION - COMPRESS FILE
Func CompressFile($FDate,$APP)
    Run(@ComSpec & " /c " & "7z.exe a -y " & $Backups & "\" & $APP & "_" & $FDate & ".7z " & $Temp & "\*", $Tools, @SW_HIDE)
EndFunc

;FUNCTION - CLEAR TEMP DIRECTORY
Func Cleanup()
    DirRemove($Temp & "\",1)
    DirCreate($Temp)
EndFunc

Func _ConvertMacroFromString($s_str); Cheap version, think I wrote an elaborate one once
    Local $a_macros = StringRegExp($s_str, "(\@\w+)", 3)
    If @error Then Return SetError(1, 0, $s_str)
    Local $s_macro, $s_escape = "(\.|\||\*|\?|\+|\(|\)|\{|\}|\[|\]|\^|\$|\\)"
    For $i = 0 To UBound($a_macros) - 1
        $s_macro = Execute($a_macros[$i])
        If @error Or $s_macro = "" Then ContinueLoop
        $s_macro = StringRegExpReplace($s_macro, $s_escape, "\\$1")
        $s_str = StringRegExpReplace($s_str, _
            "(\A|\W)(" & $a_macros[$i] & ")(\W|\z)", _
            "$1" & $s_macro & "$3")
    Next
    Return $s_str
EndFunc

Here's the INI file:

[Data]
Name = MP3Tag
Path = @UserProfileDir\AppData\Roaming\Mp3tag
Edited by niteshade

Share this post


Link to post
Share on other sites
Juvigy

So why dont you use only "\AppData\Roaming\Mp3tag" from the ini file and then concatenate @UserProfileDir in autoit like

$realpath=@UserProfileDir&path

Share this post


Link to post
Share on other sites
niteshade

Thanks ... should have done that earlier. Knew I was being stupid somewhere along the lines.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×