Sign in to follow this  
Followers 0
Jat421

Delete File

4 posts in this topic

#1 ·  Posted (edited)

Hi,

Any reason why I can't delete a file with FileDelete() when the path is passed to it from IniRead()?

INI file entry

[DEL]
DEL="@UserProfileDir & "\Desktop\Program.exe""

Code

$Del = IniRead("C:\Program\Version.ini", "DEL", "DEL", "")
FileDelete($Del)
Edited by Jat421

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

"@UserProfileDir & "\Desktop\Program.exe""

This is a literal string. The macro is not translated. I'll have a look at a workaround.

edit: Remove the outer quotes in your ini file and run this:

$PathString = IniRead("C:\Program\Version.ini", "DEL", "DEL", "") ;reads the key
$FilePath = Execute($PathString) ;executes the string as if it where code (that's as clear as I can make this sorry)
FileDelete($FilePath) ;delete the file

Inifile should look like this:

[DEL]
DEL=@UserProfileDir & "\Desktop\Program.exe"
Edited by Tvern

Share this post


Link to post
Share on other sites

This will not work because the path string is invalid. The macro @UserProfileDir will not be replaced with the actual value.

You have 2 options:

1. check the Opt() parameter: ExpandVarStrings.

2. Form a correct Filedelete() string and use Execute().

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

"@UserProfileDir & "\Desktop\Program.exe""

This is a literal string. The macro is not translated. I'll have a look at a workaround.

edit: Remove the outer quotes in your ini file and run this:

$PathString = IniRead("C:\Program\Version.ini", "DEL", "DEL", "") ;reads the key
$FilePath = Execute($PathString) ;executes the string as if it where code (that's as clear as I can make this sorry)
FileDelete($FilePath) ;delete the file

Inifile should look like this:

[DEL]
DEL=@UserProfileDir & "\Desktop\Program.exe"

That worked like a Charm!!!. Thanks a lot for your help!!!. Still learning from the pros :mellow:

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  
Followers 0