Run script through all sub folders
Run script through all sub folders
Does anyone know of a way to run a script through all subfolders of currently selected folder?
I currently have a batch script thats called that will convert image files using imagemagick. I would also like the ability to select for it to run through all subfolders but each prompt that opens needs to wait for the last to close otherwise it will not be able to convert.
I currently have a batch script thats called that will convert image files using imagemagick. I would also like the ability to select for it to run through all subfolders but each prompt that opens needs to wait for the last to close otherwise it will not be able to convert.
Re: Run script through all sub folders
There are more than one way to run through all files that are inside subfolders of the current folder.
Take a look at folderreport() to get a list of all files in subfolders.
Regarding the wait until something is finished:
The script command run has a wait parameter.
Take a look at folderreport() to get a list of all files in subfolders.
Regarding the wait until something is finished:
The script command run has a wait parameter.
One of my scripts helped you out? Please donate via Paypal
Re: Run script through all sub folders
Code: Select all
$parentDir = <xynewitems>;
$subDirs = folderreport("dirs", r, $parentDir, r);You'll then exec your converter script inside a foreach loop:
Code: Select all
foreach ($sub, $subDirs, <crlf>){
//foreach (image files in $sub){
//run "conversion command";
}
}waiting for a (cmd) prompt to close before continuing the script:
Code: Select all
run "%ComSpec% /k echo Hello, Goodbye",,1 /*or 2*/,1; echo "next script command";Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Re: Run script through all sub folders
so i created:
It runs the batch files twice in the same parent folder. I expect it to run 4 times - once for the parent, 2 for subdirectories, 1 for subsubdirectory.
I first tried without the wait but it was the same result.
Code: Select all
" Generate Sheet";
"-"
Run "C:\Sheet.bat";
"-"
"All Dir Test";
$parentDir = <xynewitems>;
$subDirs = folderreport("dirs", r, $parentDir, r);
foreach ($sub, $subDirs, <crlf>){
//foreach (image files in $sub){
run "C:\Sheet.bat";
wait 2000;
}
}I first tried without the wait but it was the same result.
Re: Run script through all sub folders
Show us the content of the $subDirs variable.
One of my scripts helped you out? Please donate via Paypal
Re: Run script through all sub folders
And $subDirs excludes the parent folder itself...
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Re: Run script through all sub folders
Your run command does not specify the working directory so it will always run in the current path.
Try this instead:
Other notes:
Hope that helps!
Try this instead:
Code: Select all
"All Dir Test"
$parentDir = <xynewitems>;
$subDirs = folderreport("dirs", r, $parentDir, r);
foreach ($sub, $subDirs, <crlf>){
run "C:\Sheet.bat", $sub;
wait 2000;
}- The script you posted actually contains 3 scripts:
- Generate Sheet
- Run "C:\Sheet.bat";
- All Dir Test
- There's no need to put a semi-colon after the caption/label of a script.
- Instead of using the wait command you can have the Run command wait until the batch file completes before continuing, by using its wait parameter.
Code: Select all
"Generate Sheet"
Run "C:\Sheet.bat";
"-"
"All Dir Test";
$parentDir = <xynewitems>;
$subDirs = folderreport("dirs", r, $parentDir, r);
foreach ($sub, $subDirs, <crlf>){
// Run C:\Sheet.bat in $sub and show a message box while we wait for it to complete.
// Change 1 to 2 in the next line to wait without the message box.
run "C:\Sheet.bat", $sub, 1;
}Re: Run script through all sub folders
Thank you for this. I will test it as soon as I get home.
After this properly runs through sub directories, I'll post the finished results with the batch files so that others can use it as well.
What I am doing:
I found that when an image is named 'folder.jpg' in a folder, that image will show as the folder thumbnail for the directory. I am using imagemagick and montage to create an index sheet containing the first 6 images in the directory, naming the index sheet folder.jpg, and then hiding the file. This produces a nice thumbnail image of photo directories in XYplorer. Eventually I will add options in the script for additional customization through a GUI.
There is probably an easier way to go about batch generating index sheets but I couldn't find anything this customizable. Also, I like being able to fully integrate it with XY.
After this properly runs through sub directories, I'll post the finished results with the batch files so that others can use it as well.
What I am doing:
I found that when an image is named 'folder.jpg' in a folder, that image will show as the folder thumbnail for the directory. I am using imagemagick and montage to create an index sheet containing the first 6 images in the directory, naming the index sheet folder.jpg, and then hiding the file. This produces a nice thumbnail image of photo directories in XYplorer. Eventually I will add options in the script for additional customization through a GUI.
There is probably an easier way to go about batch generating index sheets but I couldn't find anything this customizable. Also, I like being able to fully integrate it with XY.
-
klownboy
- Posts: 4403
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440
Re: Run script through all sub folders
Hi jdev21, I've been using the folder.jpg trick to display the folder, but your montage file called folder.jpg sounds like a nice idea especially if done on the fly on multiple folders recursively. I certainly would want to do it manually. Please post when you get it done or ask if you need any help. You could probably use XYplorer scripting exclusively to run ImageMagick on those 6 (or whatever) image files to create the montage and eliminate the need for the batch file. There are plenty of command line examples of using IM with XY on the forum.
I have an old script that does nearly the same thing but uses Irfanview in lieu of IM. I searched but couldn't easily find it. I believe it was serendipity who wrote it, but I may be wrong. It uses 12 images, or 4 if 12 aren't available, though 12 may be too many visually as a thumbnail.
Edit: Here's the script I mentioned above (it was posted by serendipity) 5 years ago and it still works. Though it appears some improvements could be made in the scripting based on all the changes in 5 years. http://www.xyplorer.com/xyfc/viewtopic. ... ils#p32267 Essentially the same idea but using Irfanview.
I have an old script that does nearly the same thing but uses Irfanview in lieu of IM. I searched but couldn't easily find it. I believe it was serendipity who wrote it, but I may be wrong. It uses 12 images, or 4 if 12 aren't available, though 12 may be too many visually as a thumbnail.
Edit: Here's the script I mentioned above (it was posted by serendipity) 5 years ago and it still works. Though it appears some improvements could be made in the scripting based on all the changes in 5 years. http://www.xyplorer.com/xyfc/viewtopic. ... ils#p32267 Essentially the same idea but using Irfanview.
Re: Run script through all sub folders
Sorry I haven't replied sooner, I got pretty busy.
I did finish up the script and I ended up changing it to produce 15 images instead of just 6 for a sheet. It is a fairly simple script (only about 15-20 lines) but requires manual editing if any changes are needed. I'll post it tonight when I get home but it may be harder to edit for those unfamiliar with command-line. I don't plan on creating any type of GUI for it. I currently have the option available (in XY) to only do the current folder or to do the current folder AND all subfolders.
The script works really well and will go through every sub-folder creating sheets. I found the original problem was using <xynewitems> (not grabbing the right directory). I had to change it to something like <curpath>... I don't remember the exact variable at the moment.
The only problem right now is that XY cannot really be used while its processing (and no easy way to stop it). A command prompt will pop up for each folder and disappear so as soon as a new command window pops up, it takes the focus. The good thing is that each folder only takes a fraction of a second to go through. It can do hundreds of folders in just a couple minutes.
I took a look at the script on the other page. I wish I would have found that sooner but I think I'm happy with what I've produced.
I did finish up the script and I ended up changing it to produce 15 images instead of just 6 for a sheet. It is a fairly simple script (only about 15-20 lines) but requires manual editing if any changes are needed. I'll post it tonight when I get home but it may be harder to edit for those unfamiliar with command-line. I don't plan on creating any type of GUI for it. I currently have the option available (in XY) to only do the current folder or to do the current folder AND all subfolders.
The script works really well and will go through every sub-folder creating sheets. I found the original problem was using <xynewitems> (not grabbing the right directory). I had to change it to something like <curpath>... I don't remember the exact variable at the moment.
The only problem right now is that XY cannot really be used while its processing (and no easy way to stop it). A command prompt will pop up for each folder and disappear so as soon as a new command window pops up, it takes the focus. The good thing is that each folder only takes a fraction of a second to go through. It can do hundreds of folders in just a couple minutes.
I took a look at the script on the other page. I wish I would have found that sooner but I think I'm happy with what I've produced.
Re: Run script through all sub folders
run command, [directory], [wait=0], [show=1]A command prompt will pop up for each folder and disappear so as soon as a new command window pops up, it takes the focus
show = 0...
One of my scripts helped you out? Please donate via Paypal
Re: Run script through all sub folders
Thanks for that highend. My next step is to add a progress bar.highend wrote:run command, [directory], [wait=0], [show=1]A command prompt will pop up for each folder and disappear so as soon as a new command window pops up, it takes the focus
show = 0...
folderjpg.xys
Code: Select all
" Generate Image Index Sheet (Current Folder) |:refresh : THUMB_REFRESH";
run "<xyscripts>\folderjpg.bat",.,0,0;
"-"
" Generate Image Index Sheet (Current Folder and ALL Subs) |:refresh : THUMB_REFRESH"
$parentDir = <curpath>;
$subDirs = folderreport("dirs", r, $parentDir, r);
foreach ($sub, $subDirs, <crlf>){
run "<xyscripts>\folderjpg.bat",$sub,1,0;
}
Code: Select all
@echo off
setlocal
IF EXIST folder.jpg attrib -h folder.jpg && del /F folder.jpg
set /a "n=0, limit=15"
>"filelist.txt" (
for /f "eol=: delims=" %%F in ('dir /on /b *.jpg *.bmp *.jpeg *.png') do (
echo '%%F'
2>nul set /a "n+=1, 1/(limit-n)"||goto :break
)
)
:break
montage @filelist.txt -geometry "400x500+3+3" -background gray -tile 5x3 folder.jpg
attrib +h folder.jpg
del filelist.txt
exit
- Attachments
-
- folderjpg.zip
- (962 Bytes) Downloaded 238 times
-
klownboy
- Posts: 4403
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440
Re: Run script through all sub folders
Hi jdev21, that's an impressive use of DOS command line to obtain the filelist. As far as the output using IM montage though I think I'd rather obtain a folder montage without any gaps or borders. I may toy with the montage parameter's to adjust the output.
Thanks,
Ken
Thanks,
Ken
Re: Run script through all sub folders
Have had great fun creating scriptlets to achieve near same results,without bat file.
http://www.xyplorer.com/xyfc/viewtopic. ... 36#p114036
http://www.xyplorer.com/xyfc/viewtopic. ... 36#p114036
totmad1 (totally mad one)
Re: Run script through all sub folders
To create a sheet without borders or padding, remove the +3+3 from the montage line.klownboy wrote:Hi jdev21, that's an impressive use of DOS command line to obtain the filelist. As far as the output using IM montage though I think I'd rather obtain a folder montage without any gaps or borders. I may toy with the montage parameter's to adjust the output.
Thanks,
Ken
Code: Select all
montage @filelist.txt -geometry "400x500" -background gray -tile 5x3 folder.jpg
XYplorer Beta Club