#148019 - 2005-09-19 11:16 AM
Rightclick and work with several files.
|
Finbom
Fresh Scripter
Registered: 2003-06-27
Posts: 21
|
Hi!
I am working on a script that lets the user select one or several files in the windows explorer, rightclick and select "send to Archive". When they select this a kix-script moves the files to a selected destination.. this works fine but the script runs one time for each file.
Does anyone know how I can make the script understand that more than one file is selected and only run the scrpt once? Hope you understand what I mean.
Regards, Magnus Finbom
|
Top
|
|
|
|
#148021 - 2005-09-19 03:42 PM
Re: Rightclick and work with several files.
|
Finbom
Fresh Scripter
Registered: 2003-06-27
Posts: 21
|
hmmm. can be tricky. To make it more difficult. Before the archiving, the user is asked for a archive-number , this is the name for the folder that the files are sent to. And I dont want the user to be needing to type the number for each file.
regards, magnus finbom
|
Top
|
|
|
|
#148030 - 2005-09-20 10:37 AM
Re: Rightclick and work with several files.
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Well, imagine:
- Process A checks the file and there is no master.
- Process B checks the file and there is no master.
- Process A writes a key to say that it is a master.
- Process A checks the key to ensure that it is still master.
- Process B writes a key to say that it is a master.
- Process B checks the key to ensure that it is still master
Now, both processes think that they are masters.
You could introduce a sleep after writing the key. In this case Process A would see that process B had overwritten the master key so it would demote itself to a slave. In most cases this would probably work. This technique fails when the master process dies without completing it's task. To guard against this you would need all the slave processes to monitor the master and go through the master election process if the master dies.
Using a lock file makes the whole thing much more simple.
The example here will allows one arbitrary process to become the master. Only one process can become a master because of the atomic nature of locking a file in write mode.
If the master process it killed off then a slave will automatically promote itself to master status and complete the work. Slaves will only exit when their file has been serviced which means that as long as there is at least one slave left the job will be completed.
For this example I have not added code to lock the INI file while writing - I've no reason to believe it is necessary for local INI files. SingleStream.kix Code:
Break ON $=SetOption("Explicit","ON") ; NB Pass the parameter on the command line as "$sFILE" Dim $iIsMaster Dim $sIni,$sLatch,$sInput,$sUnique,$sFileSection $sLatch=".\LatchFile.TXT" $sIni=".\IPC.INI" $sFileSection="FILELIST" ; Generate a unique key for IPC comms $sUnique=CSTR(@PID)+"."+@DATE+"."+@TIME+"."+@MSECS+"."+@TICKS If Not IsDefined($sFile) "No parameter $$sFile passed on command line - aborting"+@CRLF Exit 1 EndIf ; Write parameter to IPC $=WriteProfileString($sIni,$sFileSection,$sUnique,$sFile) ; We will either become the master process, or we will wait for the master process to action our file While ReadProfileString($sIni,$sFileSection,$sUnique)<>"" And Not $iIsMaster If Not $iIsMaster $iIsMaster=FreeFileHandle() If Open($iIsMaster,$sLatch,1+4) $iIsMaster=0 Sleep 0.1 ; Give the CPU a break! Else ; Check again to avoid race conditions If ReadProfileString($sIni,$sFileSection,$sUnique)<>"" "Process "+@PID+" has become the master, enter a string to continue: " GetS $sInput Else $=Close($iIsMaster) $iIsMaster=0 EndIf EndIf EndIf Loop ; If we are the master process then we need to action the file list, otherwise our job is done. If $iIsMaster For Each $sUnique in Split(ReadProfileString($sIni,$sFileSection,""),Chr(10)) If $sUnique $sFile=ReadProfileString($sIni,$sFileSection,$sUnique) "Slave process # "+Split($sUnique,".")[0]+" has asked master to deal with '"+$sFile+"'"+@CRLF ; ; *************************** ; * Do file processing here * ; *************************** ; ; Delete file key to release slave $=WriteProfileString($sIni,$sFileSection,$sUnique,"") EndIf Next "Hit return to exit: " GetS $ Else "Slave process "+@PID+" released."+@CRLF EndIf ; vim: ts=4 sw=4 fdc=4 fdm=marker ai
Test batch file: SingleStreamTest.bat Code:
Start "Single stream test file ONE" kix32.exe SingleStream.kix $sFile="This is file one" Start "Single stream test file TWO" kix32.exe SingleStream.kix $sFile="This is file two" Start "Single stream test file THREE" kix32.exe SingleStream.kix $sFile="This is file three" Start "Single stream test file FOUR" kix32.exe SingleStream.kix $sFile="This is file four"
|
Top
|
|
|
|
#148031 - 2005-09-22 03:04 PM
Re: Rightclick and work with several files.
|
Finbom
Fresh Scripter
Registered: 2003-06-27
Posts: 21
|
A breakthrough.. or at least a workaround.
I found out that if I skip the right-click option and use the right-click "SendTo"-feature it works better. I have an shortcut for a very simple cmd-file that simply echoes all selected files to an text-file.
Now I wonder two things. 1.How do I get the variables from the commandline into the kix-script. 2.How do I make the script to know how many files selected?
A progress. :-)
regards, Magnus Finbom
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 515 anonymous users online.
|
|
|