I'm trying to create a slideshow from all pictures located in a directory with many subdirectories.
The guides I found only work on windows 10, not 11
I found that I can create a directory with hard links which takes very little space, and then point windows to that directory
The following script will find all jpg files and save their link in the target dir
save this script as script.bat:
SETLOCAL ENABLEDELAYEDEXPANSION
cd <your\root\image\folder\>
set m=0
for /R %%f in (*.jpg /b) do (
echo !m!
mklink "<your\target\dir\!m!.jpg" "%%f"
set /a m = !m!+1
)
and run
Related
I have already solved my question... What I haven't solved is how to do this if the .bat file is located in a parent folder and that it should work on all subfolders?
Right now, there's a limitation that it only create folders if the .bat file is located in the same folder as the files. It can't create folders if the files are inside a subfolder.
What I have is:
the filename of this .bat is :
organize.bat
#echo off
for %%i in (*) do (
if not "%%~ni" == "organize" (
md "%%~ni" && move "%%~i" "%%~ni"
)
)
How I do it right now:
I place the .bat file in a folder together with the files
When I click it, it will create folders with a name based on the files inside that folder
It will also move each files in those folders of the same name
What I need:
Place the .bat file in the main folder with many subfolders containing the files
Click it to perform the same tasks above
Apologies if my explanation is confusing... I hope it's still understandable.
Thank you in advance!
Your attempt is very close to working but beware the wrinkles of using a simple approach without checking each detail so, start here:-
#echo off & Title %~n0
REM I recommend using cd /d "%~dp0" to ensure you start from the known cmd file folder location not some system folder
cd /D "%~dp0"
REM add the /R switch to run through subdirs
for /R %%i in (*) do (
REM replace organize to %~n0 so as to aid renaming by other users
if not "%%~DPni" == "%~DPn0" (
REM to allow for nested paths we need a fuller DP location for N (check it works exactly as desired then remove the echos)
echo md "%%~DPni" && echo move "%%~i" "%%~DPni"
)
)
BEWARE files with double .dot.s such as cmd.exe.lnk so check those echo's first
md "C:\Users\me\Favorites\Links\cmd.exe"
move "C:\Users\me\Favorites\Links\cmd.exe.lnk" "C:\Users\me\Favorites\Links\cmd.exe"
I still have not solved why this code which correctly runs through all the sub folders, looking for jpg files to convert to pdf files and compresses them but exits before executing any command after the final ')'. It is definitely due to ps2pdf but can't think of what ps2pdf can be changing. Any ideas?
#echo on
set records="C:\Users\john\Documents\0 BDHS Digitised records\Awaiting processing\"
cd %records%
setlocal enabledelayedexpansion
for /r . %%G in (.) do ( Pushd %%G
If %errorlevel% NEQ 0 goto:eof
rem merge jpgs to PDF
jpeg2pdf.exe *.jpg -o "%%~nG".pdf
set fname=%%G
ps2pdf -dPDFSETTINGS#/ebook "%%~nG".pdf "%%~nG"compressed.pdf
popd )
echo Ended
pause
Here is an example of your script, with the required Call for your ps2pdf.bat file.
Before running it, please substitute the correct full paths for your executable utility, jpeg2pdf.exe, (line 14), and script ps2pdf.bat, (line 15). It is not a good idea to rely on modifiable registry or environment variables hence the reason I'm advising their full paths. If those two files will always be located in the directory of this batch file, or relative to it, feel free to use %~dp0 in designating those paths.
#Echo Off
SetLocal DisableDelayedExpansion
Set "records=%UserProfile%\Documents\0 BDHS Digitised records\Awaiting processing"
Set "fname="
If Exist "%records%\" (
For /R "%records%" %%G In (*.jpg) Do (
SetLocal EnableDelayedExpansion
If Not "!fname!" == "%%~dpG" (
EndLocal
Set "fname=%%~dpG"
For %%H In ("%%~dpG.") Do (
Rem Merge JPGs to PDF
"P:\athTo\EXE\jpeg2pdf.exe" "%%~dpG*.jpg" -o "%%~dpG%%~nxH.pdf"
Call "P:\athTo\ps2pdf.bat" -dPDFSETTINGS#/ebook "%%~dpG%%~nxH.pdf" "%%~dpG%%~nxHcompressed.pdf"
)
) Else EndLocal
)
Echo Ended.
) Else Echo Directory %records% dos not exist.
Pause
The example above, has been made more efficient, by only recursing through directories which contain files with .jpg extensions.
The script however does not step in an out of directories using PushD and PopD, as did yours. Whilst this may be a slight improvement efficiency wise, it may bring rise to another issue. As I do not know your utilities, if they only accept limited length commandlines or paths, this version could choke.
I have around 12,000 .jpg files in a data-set folder in G:\train with names such as
0002_c1s1_000451_03.jpg, 0002_c1s1_000551_01.jpg...
up to
...1500_c6s3_086542_02.jpg , 1500_c6s3_086567_01.jpg
I want to move them to new folders with their initial filename such as 0002, 0005, 0007,... 1496, 1500
What I need is a Windows batch file to create new folders & move files quickly without a hassle. I've tried few other answers to no avail.
Something like this should do, as a .cmd/.bat script file:
#rem The DEBUG_RUN variable enables a step-by-step mode, it will cause the
#rem script to pause after processing every file. Remove the DEBUG_RUN (and
#rem the pause instruction) when you are confident it does what you want,
#rem restart the script and enjoy :-)
:main
#setlocal
#set DEBUG_RUN=1
#pushd "G:\train"
#for %%f in (*.jpg) do #(
call :mvToSubDir "%%~nxf"
if defined DEBUG_RUN pause
)
#popd
#pause
#endlocal
#goto:eof
:mvToSubDir
#set fn=%~1
#set dn=%fn:~0,4%
#if not exist "%dn%" mkdir "%dn%"
move "%fn%" "%dn%"
#goto:eof
you can try a series of for loops to accomplish this
for /l %%f in (1,1,12000) do (
mkdir %%f
for %%d in (c:\sourcedir) do (
move %%d %%f
)
)
i didn't fully understand how you wanted to sort them but i hope this helps. You can use the "for /?" command and feel free to ask for more help if this isn't enough. I wish you luck with your endeavors.
I am on Windows 10. I have a folder with sub folder. All subfolders have "Subs" folder inside them. I want to loop through all subdirectories, goto Subs directory, unrar a file, Goto next subdirectory and repeat.
I tried below script but could not get to work.
#echo off
setlocal enableextensions enabledelayedexpansion
set "rootFolder=C:\Users\MNM\MAT"
echo ----------------------------------------------------------------------
for /d /r "%rootFolder%" %%a in (.) do (
set mypath=%cd%
#echo %mypath%
cd %%a
set mypath=%cd%
#echo %mypath%
cd Subs
set mypath=%cd%
#echo %mypath%
C:\Users\MNM\MAT\unrar e *subs.rar C:\Users\MNM\mat2\
cd C:\Users\MNM\MAT
)
This simple task can be done with just a single command line:
#echo off
for /R "%USERPROFILE%\MAT" %%I in ("*subs.rar") do "%USERPROFILE%\MAT\UnRAR.exe" x -c- -idcdp -y "%%I" "%USERPROFILE%\mat2\"
USERPROFILE is a predefined Windows Environment Variable which is on your computer for your user account defined with value C:\Users\MNM.
The command FOR searches in directory C:\Users\MNM\MAT and all its non hidden subdirectories because of /R for non hidden files matching the pattern *subs.rar. Each file name found is assigned with full path to loop variable I.
UnRAR is executed for each found RAR archive file for extracting the archive to directory C:\Users\MNM\mat2 with extracting also the directory structures inside the RAR archive file because of command x instead of e. Existing files in destination directory (tree) are automatically overwritten because of -y. The switches -c- and -idcdp are for displaying less information during extraction process.
For a brief description of used and additionally available switches of UnRAR run in command prompt window UnRAR without any parameter or with /? as parameter. A complete description of the commands and switches of UnRAR can be found in text file Rar.txt in program files folder of WinRAR if that shareware application is also installed and not just the freeware UnRAR.
It is absolutely not needed to change into the directory containing the RAR archive file on extracting all RAR archives into same destination directory as it can be seen here.
This is one possible way if I understood your folder structure correctly:
#echo off
set "Base=C:\Users\MNM\MAT"
echo ----------------------------------------------------------------------
for /F "delims=" %%A in (
'dir /B/S "%Base%\*subs.rar" ^| findstr /i "^%Base:\=\\%\\[^\\]*\\Subs\\[^\\]*subs.rar$"'
) do Echo "C:\Users\MNM\MAT\unrar.exe" e "%%~fA" "C:\Users\MNM\mat2\"
the for /f will parse the output of the dir and findstr
dir will iterate all *subs.rar in the tree starting from %Base%
the complex RegEx in findstr will filter the rar's to those in a folder subs in a subfolder of %Base%
as a backslash is an escape char in a RegEx, literal backslashes have to be doubled.
If the output looks ok remove the echo in the last line.
Just because recursing all subdirectories and extracting all *subs.rar files wasn't requested here's an example that is based upon my assumptions:
#ECHO OFF
SET "rootDir=%USERPROFILE%\MAT"
IF /I NOT "%CD%"=="%rootDir%" CD /D "%rootDir%"
FOR /D %%A IN (*
) DO IF EXIST "%%A\Subs\*subs.rar" UNRAR e "%%A\Subs\*subs.rar" mat2\
I am working on a batch script which reads a file and "find and replace" this character "╡" to "µ"
So far I was able to write following code:
#echo off
Setlocal enabledelayedexpansion
chcp 65001
Set "Pattern=╡"
Set "Replace=µ"
For %%# in ("E:\CopiedVault\*") Do (
Set "File=%%~nx#"
Ren "%%#" "!File:%Pattern%=%Replace%!"
)
The problem I am facing is how I don't know how this script can be modified ,by which it can read subfolders of folder "CopiedVault", and then can find and replace files and their names.
This script works perfect if it is able to find the file.
Try
dir /s /b E:\CopiedVault
inside a forloop and for each occurance rename the file.