lundi 22 juillet 2019

How to make a powershell or batch file that picks a random file from a folder, executes it and then deletes it

I'm looking to execute a bunch of similar .ppx files on different cloud windows servers from a single common dropbox folder.

I thus need to make a script that randomly selects a file from a folder, executes it to open the Proxifier profile and then deletes the file from the folder (Dropbox folder) so when I'm setting up the next server, the same script file cannot select the previously opened .ppx file.

So far I have:

Set "SrcDir=C:\Users\Admin\Dropbox\Files"
Set "ExtLst=*.ppx"
Set "i=0"
For /F "Delims=" %%A In ('Where /R "%SrcDir%" %ExtLst%') Do (Set /A i+=1
    Call Set "$[%%i%%]=%%A")
Set /A #=(%Random%%%i)+1
Call Start "" "%%$[%#%]%%"

This picks a random file from the folder but I can't quite figure out what to add to delete that file it picked.




Aucun commentaire:

Enregistrer un commentaire