I've written a script to add timestamps to filenames. It gets run by a custom button in Classic Explorer.
I can select one or more files in Explorer, hit the button, it passes the list of selected files (placeholder %3) to my script, the script does its thing, and it passes back a list of the new filenames in the to-select file (placeholder %5).
The idea being, the same files are still selected in Explorer afterwards as before, only now they have new names. But
the selection part doesn't work. Specifically, it seems Explorer FIRST attempts to do the selecting (based on the "files to select" temporary file named in %5), and THEN refreshes its list of files. It ought to do this the other way around.
Similarly, if
I write a script to create a file and select it, the selection part fails for the same reason.
Example code to illustrate this:
Code:
rem ------------------------------------------------------------
rem newscript3.bat thundt rev 1 16-Feb-14
rem ------------------------------------------------------------
rem This creates a bogus file and puts its name into the selection file.
rem Expected result: new file foo.txt, selected by Explorer.
rem Actual result: FIRST time, the file appears but is not selected
rem SECOND time, file is selected. Hmm!
rem Conclusion: CE does not refresh its directory list until AFTER doing the selecting.
rem This breaks selection feature when running scripts that add or rename files.
rem ------------------------------------------------------------
rem Command line in CE
rem %USERPROFILE%\tmp\newscript3.bat -i %3 -s %5
rem Create some new bogus file
echo foobar> foo.txt
rem Stick its name in the selection file
echo select>%4
echo foo.txt>>%4
(The "-i" and "-s" are there because it's what I use in my renaming script. The parameters do get passed correctly.)
Less stripped-down version with more instrumentation for debugging -- you can use it to confirm the parameters get passed correctly:
Code:
rem (newscript2.bat)
set mypath=%~d0%~p0
set F=%mypath%\newscript2.log
date /t >> %F%
time /t >> %F%
echo got param 1 = %1 >> %F%
echo got param 2 = %2 >> %F%
echo got param 3 = %3 >> %F%
echo got param 4 = %4 >> %F%
echo Contents of %2 >> %F%
echo ---- >> %F%
type %2 >> %F%
echo ---- >> %F%
rem now try to run it in perl
rem C:\App\Perl\bin\perl.exe c:\winbin\fixdatecode.pl -i %mypath%\in.txt -s %mypath%\select.txt
REM C:\App\Perl\bin\perl.exe c:\winbin\fixdatecode.pl -i %2 -s %4
rem Attempt to debug the selecting-on-completion part.
rem We ignore the input file entirely.
rem Create some new bogus file
echo foobar> foo.txt
rem Stick its name in the selection file
echo select>%4
echo foo.txt>>%4
echo Contents of %4 >> %F%
echo ---- >> %F%
type %4 >> %F%
echo ---- >> %F%
call hexdump %4>>%F%
echo ---- >> %F%
(This will complain you don't have the 'hexdump' script I'm using. But ought to work, otherwise. I was trying to see if Perl was doing anything funny with the file; it was not. Straight Windows text file, just like the examples in the help.)
Sorry if this has been covered before; I wasn't able to find it.
Thanks for any help.