Jump to content


FileDelete, FileCopy, etc not allowing variables


  • Please log in to reply
5 replies to this topic

#1 Guests

  • Guests

Posted 11 April 2005 - 02:56 AM

I think this is a bug, but maybe I am doing something wrong.

Try this:
1- Create a file somewhere, such as C:\Test.txt
2- Create a simple script as follows:

var = "C:\Test.txt"
FileDelete, %var%

This will not work for me - ErrorLevel gets set to 1 and the file is not deleted. If I get rid of the variable, and just type:
FileDelete, C:\Test.txt
it works fine.

FileCopy and FileMove are similar - they are not allowing for variable references in their parameters.

Tom Boughner

#2 corrupt

corrupt
  • Members
  • 2558 posts

Posted 11 April 2005 - 02:59 AM

var := "C:\Test.txt" 
FileDelete, %var%
Does this work?

#3 Serenity

Serenity
  • Members
  • 1271 posts

Posted 16 April 2005 - 01:34 PM

Try removing the quotes around the variables contents:

var = C:\Test.txt
FileDelete, %var%


#4 RandomCoder

RandomCoder
  • Guests

Posted 10 July 2012 - 11:55 PM

I been making this program for awhile & today for some godly reason gave me this same exact problem.

Originally everything worked ok, however the part of my script was designed to DELETE TASK, then REWRITE the new task by deleting a single row from the whole file list. However it wouldnt delete the file anymore so it just kept appending the file, and everything really started getting out of order fast.

Anyways the Solution i came up with this, was instead of writing to the origional file, i created a .tmp file same name, then used the FILECOPY to copy the .tmp file & replace origional .ini file. FILECOPY must have the overwrite opition selected which is an extra ,1 to the end of FILECOPY.

Hope this helps someone else who runs into this problem.

#5 RandomCoder

RandomCoder
  • Guests

Posted 11 July 2012 - 12:00 AM

Here is the Example: (note im reading from an .ini file, creating a .tmp file to hold the new data, then transferring the new date in the .tmp file & replacing the original .ini file. So this also bypasses the deleting of the .ini file, but instead purely replaces it with the data in the tmp file.)


IfExist,%A_MyDocuments%\Task.tmp
FileDelete,%A_MyDocuments%\Task.tmp
IfNotExist,%A_MyDocuments%\Task.tmp
FileAppend,%TASK_REWRITE%, %A_MyDocuments%\Task.tmp

FileCopy,%A_MyDocuments%\Task.tmp,%A_MyDocuments%\Task.ini,1

#6 Morpheus

Morpheus
  • Members
  • 397 posts

Posted 12 July 2012 - 11:35 AM

To me it looks like you are doing the same thing as before. You are still deleting, and appending to a file.
I would put the If exist in a loop.

IfExist,%A_MyDocuments%\Task.ini
FileDelete,%A_MyDocuments%\Task.ini
Flag = 0
Loop, 50
{
IfExist,%A_MyDocuments%\Task.ini
  Sleep, 20
}
Else
{
  Flag = 1
  FileCopy,%A_MyDocuments%\Task.tmp,%A_MyDocuments%\Task.ini,1
}
If Flag = 0
   MsgBox, Error: Unable to create new file.