Jump to content

Delete File


Recommended Posts

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
Link to comment
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"
Edited by Tvern
Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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:

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...