View Full Version : help with deleting stuff
element78
10-23-2003, 10:03 PM
Sorry for another post, but I think i might more views if I did it this way :)
OK, my AMS project is designed to copy a bunch of temporary files to a local temp directory, then when its finished, delete the ones it copied.
My question to you is: is there ANY way to get AMS to delete multiple files without making a new delete dialog pop up for each file? That's a bit repetitive..
I have tried editing the delete action's XML by adding <ShowDialog>0</ShowDialog> (or whatever it is, something like that)..
That doesn't work.
I tried using a function from kernel32.dll (DeleteFileA):
%DLLResult% = File.CallDLLFunction ( "%SysDir%\kernel32.dll", "DeleteFileA", ""%file2del%",1,0")
<IR_ACTIONS_LIST>
<Action name="Call DLL Function">
<Type>143</Type>
<Function>0</Function>
<DTIndentLevel>0</DTIndentLevel>
<Enabled>1</Enabled>
<ErrorHandling>
<UserNotificationMode>2</UserNotificationMode>
<CustomErrorMessage/>
<OnErrorAction>0</OnErrorAction>
<JumpToLabel/>
</ErrorHandling>
<FileName>%SysDir%\kernel32.dll</FileName>
<FunctionName>DeleteFileA</FunctionName>
<FunctionParameters>"%file2del%",1,0</FunctionParameters>
<ReturnType>2</ReturnType>
<CallingConvention>1</CallingConvention>
<Variable>%DLLResult%</Variable>
</Action>
</IR_ACTIONS_LIST>
But all I get out of that is some kind of "Access violation, this program will not terminate" error. (Windows 2000)
(%file2del% is the full path + filename.ext)
Please help, this one's buggin' me! :confused:
I've needed a way around this several times now, but never could get any solid help on the issue.
And if at all possible I'd rather not have to use a batch file...
ty! :)
P.S. check out my new site layout I'm working on and let me know what you think! http://pixelwise.does.it/ Only the graphics and basic layout are finished so far.. but if you have any suggestions let me know :)
I must not understand, because from this description it seems like you could just delete the whole folder at once. A single action and all the files are gone.
yosik
10-24-2003, 05:24 AM
And if you want to delete only selected files, you could select them, create a directory, move the files there and delete the directory.
Yossi
This may help...
Folder Manipulation DLL (http://www.indigorose.com/forums/showthread.php?s=&threadid=2778&highlight=folder+manipulation)
You'll have to have all your files in a folder, then simply use the DLL to remove the folder, it's subfolders, and files. :)
element78
10-24-2003, 01:23 PM
Ok, thanks for the help guys but I don't think you understand my question completely.
The files that will be deleted are not always the same, so deleting an entire folder would not work (some files have different paths than others, based on user prefrence). And yossi, moving all the files then removing them would not work either, I already thought about that. Because instead of a bunch of delete dialogs popping up, a bunch of move dialogs would pop up.
Pretty much what I need to do is set up a while loop to delete the files that were placed into the listbox, but avoiding having a
zillion new delete boxes pop up.
Idealistically, it would be nice be able to use a delimited list of filenames with their unique paths, to add to the File > Delete File action, but AMS was not built to do that, they have to be done one by one.
Hopefully that will clear things up a little. It's a bit difficult to explain.
Here's a simple while loop i put together to try to explain better:
%itemstoremove% = ListBoxObject[ListBox1].GetProperty ("Item Count")
%filecounter% = "0"
WHILE (%filecounter% < %itemstoremove%)
%path% = ListBoxObject[ListBox1].GetItemText (%filecounter%)
File.Delete ("%path%") <--- THAT is where the problem is, it opens a new dialog for each file
%filecounter% = Evaluate (%filecounter% + 1)
END WHILE
thanks,
-Adam
TJ_Tigger
10-24-2003, 01:45 PM
Adam,
What it looks like is happening is when you select an item in the ListBox is will only delete that one item. That is why you are seeing multiple delete options. If you want to select one item and remove all the items that are in that folder you may want to use the String.ParsePath function, like this:
%path% = String.ParsePath ("%path%", DriveAndFolder)
That will remove the file name and leave only a Drive and Folder that contained the file. If you then use the Folder.Remove to remove the folder that should work for you.
Folder.Remove ("%path%")
One item to watch out for is if you have multiple items in your listbox from the same folder. You may want to run some additional scripts that will refresh what is listed in your ListBox.
HTH
Tigg
element78
10-24-2003, 01:56 PM
:mad: That wont work either.. because like i said at the top of that reply, some files will stay put, some will be removed. It all depends on the prior user prefrences. Deleting an entire folder would delete things they didnt want removed. I just need specific files removed, some with different paths, etc.
The listbox contains for example:
c:\winnt\temp\blah.txt
c:\documents and settings\??USER??\Local Settings\Temp\blahblah.avi
c:\winnt\sneeze\blah2.txt
See where I'm getting at? Its confusing the heck out of me.
TJ_Tigger
10-24-2003, 02:19 PM
It is too bad that you could not delete files based on a delimited string without running through a while loop.
Here's a quick DLL to do that TIG. The delimiter must be a ;;
This will try to delete the file, if it can't it moves on. The return will always be a 0. Sorry, I don't have much time to pretty it up.
Sample Call:
%DLLResult% = File.CallDLLFunction ( "%SrcDir%\dellist.dll", "DelFiles", ""C:\test.txt;;C:\Sample Folder\test.txt"")
Cut and Paste:
<IR_ACTIONS_LIST>
<Action name="Call DLL Function">
<Type>143</Type>
<Function>0</Function>
<DTIndentLevel>0</DTIndentLevel>
<Enabled>1</Enabled>
<ErrorHandling>
<UserNotificationMode>2</UserNotificationMode>
<CustomErrorMessage/>
<OnErrorAction>0</OnErrorAction>
<JumpToLabel/>
</ErrorHandling>
<FileName>%SrcDir%\dellist.dll</FileName>
<FunctionName>DelFiles</FunctionName>
<FunctionParameters>"C:\test.txt;;C:\Sample Folder\test.txt"</FunctionParameters>
<ReturnType>0</ReturnType>
<CallingConvention>1</CallingConvention>
<Variable>%DLLResult%</Variable>
</Action>
</IR_ACTIONS_LIST>
Sample Call:
Protocol
10-24-2003, 04:03 PM
Hi there Element,
I know exactly what you're talking about. I'm going through the same exact problem right now.
I have a user multi-selecting items from a listbox, then enabling them to delete the randomly selected items in bulk. The problem is that I sometimes have up to 127 files and the effect is a strobe light of dialog boxes.
I've even tried to modify the XML to disable the dialog box function.
It's not disabling to the functionality just possibly a legal issue when 100,000 people go into epileptic shock. :eek:
Worm can figure it out. Worm's the man. Well...Worm's a worm, but he can solve all your problems.
Protocol
element78
10-24-2003, 04:37 PM
Worm, you never stop amazing me!!!!
Thanks so much, i'll give it a try!
No prob. Sorry I haven't been around as of late. But its a busy time for me. Good and bad, you all know the drill.
Element, you might look into the CopyFileA function in the Kernel32.dll to copy files without the dialog. I use it all the time to avoid the flashing dialog syndrome.
CopyFileA (http://www.mentalis.org/apilist/CopyFile.shtml)
Protocol, check out the DeleteFileA function in the Kernel32.dll for deleting without dialogs.
DeleteFileA (http://www.mentalis.org/apilist/DeleteFile.shtml)
element78
10-25-2003, 01:32 AM
Actually, I tried DeleteFileA in kernel32, and it gave me some access denied error (and I AM administrator on this computer)
So that didn't work out so well..
Same with some shell32 function to send to recycle bin.. same error.
Figured if I got an error on my OWN computer, its not worth keeping it like that.
How're you doing on this Element? Did the DLL help or is there more to it that you need?
element78
10-27-2003, 02:29 PM
Your dll was beyond perfect.. Thanks again :)
Protocol
10-28-2003, 10:52 AM
Sent a private message, but I'm not sure if you'll get it in time...
Can you help me out with a copy-to dll call?
The delete-file one kicked! It solved the same problem element was having, which for my client was going to be a big irritation. :rolleyes:
Thanks in advance!
Protocol
The FolderManipulation DLL I wrote a while ago will copy files from one folder to another using wildcards. Here's a sample that will copy all WMV files from one folder to another.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.