Some notes:
The issue of merging files, is caused by the | character.
It causes the command line processor (CLP) to spawn 2 threads:
one executing "md group", and the other executing "move "%1" group".
Both are working in (pseudo)parallel threads, so if the second is performed first,
it renames the file,
and after that has happened all other group operations should merge
(if COPYCMD variable contains /Y), as "md" fails (name is a filename),
and "move" overwrites group as the target is no path.
Your fix with the added ping commands only seems to be corrected by the ping, but it is fixed,
because there you are using an & instead of an |.
The & advices the CLP to execute the commands inorder, first the left command and then,
after the first is finished the right one.
But if you create a file named "group" you will see, that it will do the same, as the above command line.
BijaN-R wrote:How we can use something like %TIME% or %RANDOM% for folder name ?
Just use the escaped form of %, this means %%TIME%% and %%RANDOM%% should work.
But the problem is, if you are using dynamically created directory names with unique ids,
then every file will be placed in its own directory.
The cause: The command you build is called for every single file. The program cannot guess,
that you wanted to group some files.
You can try it out using on a group of selected files:
Code: Select all
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\My Item\Command]
@="cmd /E:ON /F:ON /C \"@for %%s in (\"%1\") do @for %%t in (\"%%~dnew Folder (%%time%%)\") do @(@echo md group ^& move \"%%~s\" \"%%~t\" & pause)\""
This only displays the move operation that would be performed;
if you want no simulation, remove the echo and replace the ^& by &.
Using %%random%% should be similar (random values, but should all be different).
The only 2 things you could do were:
1) to create 2 or 3 context menu items:
1: "create file group", as system variables will be discarded, when cmd session ends, you have to use a (temp) file
2: "move group" i then would create Folders of the form "new Folder (n)" while n is increasing in [0:2^31-1]
3: "add file(s) to group"
2) to create a program that can self check if an instance of itself has been started, which you can pass a stream of filenames,
and if this stream doesn't contains a minimum names per second (you have to specify),
then it performs the grouping operation (again of the above form), and exits.
The second solution is far beyond batch file scripting.
Actually i cannot see another solution for this problem.
Btw:
BijaN-R wrote:... and sorry for my English.
This is no problem as my use of the english language is as bad, too
(And this assums that i have a good day.)
.
penpen