Hi,
I am trying to write a safe *.txt delete function.
My idea is to write a script to create a text file containing a list of all the text files starting with a "u"in a directory. (u*.txt)
Then loop through this file to delete all the text files in this directory.
This works fine, as long as SYSTEM_PUBLICATION_DIR, is not in the Program Files directory (where I want to to be).
My problem is that a dos batch file does not like using Program Files as a path, but wants Progra~1 instead. (This applies to My Documents folder as well)
I thought that the following script would work, but it gives me an error:
"Action (15, 0) : Function Not Found : Check spelling and capitalisation"
What am I doing wrong?
Regards
Neil
Code:
var wbat;
var wwbat;
var mybText;
var foundText;
wwbat = OpenFile(SYSTEM_PUBLICATION_DIR + "\\Students\\"+Student+ "\\ulist.txt",true)
//create a new file ulist.txt
wwbat.WriteLine("dir /b "+SYSTEM_PUBLICATION_DIR + "\Students\\"+Student+ "\\u*.txt > "+SYSTEM_PUBLICATION_DIR + "\Students\\"+Student+ "\\ylist.txt")
//puts the dos dir command into the file to redirect the output to a file called ylist.txt
//this will output dir /b c:\Program Files\Test\Students\12345678\u*.txt > c:\Program Files\Test\Students\12345678\ylist.txt
// won't work because Program Files needs to be Progra~1
mybText = wwbat.ReadLine()
//reads the line just written, into var mybText
wwbat.Close()
mybText.SetSelection(0,-1)
//selects the entire mybText to check for existance of "Program Files"
Debug.trace(mybText)
foundText = wwbat.FindTextInSelection("Program Files",0)
if (foundText != -1)
// if "Progam Files" is found, get start/end indexes
{
mybText.SetSelection(foundText,(foundText + 13))
//sets start/end indexes (index in var foundText and index of foundText +13 (length of charactures in "Program Files"))
mybText.ReplaceSelection("Progra~1");
// replace "Program Files" with "Progra~1" in var mybText
}
wbat = OpenFile(SYSTEM_PUBLICATION_DIR + "\\Students\\"+Student+ "\\ulist.txt",true)
//following lines write the contents of the batch file to ulist.txt, then renames ulist.txt to ulist.bat
wbat.GotoFirstLine()
wbat.WriteLine("echo on")
wbat.GotoNextLine();
wbat.WriteLine(mybText)
wbat.Close()
wait(1)
CopyFile( SYSTEM_PUBLICATION_DIR + "\\Students\\"+Student+ "\\ulist.txt",SYSTEM_PUBLICATION_DIR + "\Students\\"+Student+ "\\ulist.bat")
wait(1)
LaunchFile(SYSTEM_PUBLICATION_DIR + "\\Students\\"+Student+ "\\ulist.bat")
//runs newly create batch file to generate a list all the u*.txt files to be looped for deletion in next function