I use gallery-dl to download pics from Pixiv.com. All of the below are run from Windows' .bat files.
I manually create a folder with only {user[id]}.
Example: Pixiv - Temp\24517
I then copy gallery-dl.bat (which calls on gallery-dl.exe and the related gallery-dl.conf, elsewhere) and a number of assisting .jpg files into that folder.
Example: Pixiv-Temp\24517\gallery-dl.bat
I've done this for over 5,000 users.
Running gallery-dl.bat from within folder configured for the below, passing a variable of the folder name will download the pics as well as saving a *.sqlite3 file to the folder 24517.
gallery-dl.conf
"directory": ["{user[id]}"],
The actioning part of gallery-dl.bat (listed in whole, below).
"C:\Users\AdminS6\gallery-dl\gallery-dl.exe" -d "..\..\." --download-archive "%~dp0GDB.sqlite3" "https://www.pixiv.net/en/users/%FOLDER%/illustrations"
The current .bat file in whole:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
pushd "%~dp0" || exit /B
move /y "..\Folder2.jpg" "..\Folder.jpg"
for %%I in (..) do set "FOLDER=%%~nxI"
for /f "tokens=1 delims= " %%a in ("%FOLDER%") do set tmpFOLDER=%%a
"C:\Users\AdminS6\gallery-dl\gallery-dl.exe" -d "..\..\." --download-archive "%~dp0GDB.sqlite3" "https://www.pixiv.net/en/users/%FOLDER%/illustrations"
del "..\Folder3.jpg"
if not exist "GDB.sqlite3" move /Y "..\Folder4.jpg" "..\Folder.jpg"
if exist "GDB.sqlite3" del "..\Folder4.jpg" && del "..\Folder.jpg"
if exist "..\*.mp4" md "..\Reels" & move /y "..\*.mp4" "..\Reels\"
if exist "..\*.gif" md "..\GIFs" & move /y "..\*.gif" "..\GIFs\"
if exist "..\*.webp" md "..\WEBPs" & move /y "..\*.webp" "..\WEBPs\"
robocopy "..\..\%FOLDER%" "X:\11Web\gallery-dl\Pixiv - Temp\24517 -" *.* /e /move
TIMEOUT /T 1
popd
endlocal
I now plan to change gallery-dl.conf to {user[id]} - {user[name]}. This will result in a change to the destination folder being created now by gallery-dl. The original folder is left unchanged.
Example my original source folder: Pixiv-Temp\24517
Example gallery-dl new output folder: Pixiv-Temp\24517 - ケースワベ
gallery-dl.conf
"directory": ["{user[id]} - {user[name]}"],
gallery-dl.exe
"C:\Users\AdminS6\gallery-dl\gallery-dl.exe" -d "..\..\." --download-archive "%~dp0GDB.sqlite3" "https://www.pixiv.net/en/users/%FOLDER%/illustrations"
Not knowing how a {user[name]} will come out in Explorer folder naming, I am left to still manually create an original source folder with only {user[id]}. I will continue doing this due to ease.
The above noted change will present problems I would like to overcome:
When running gallery-dl, the pics from Pixiv will be downloaded to an Explorer folder name of {user[id]} - {user[name]}, while the original manually-created folder still hosts the gallery-dl and *.sqlite3 file. I need these combined.
When re-running/updating gallery-dl against the 5,000 other folders, I will be left with 5,000 of one {user[id]} and 5,000 of the other {user[id]} - {user[name]}.
Robocopy has shown the most promise in solving these. When run in the below .bat, gallery-dl runs and all files from {user[id]} folder are moved to {user[id]} - {user[name]} folder, leaving {user[id]} folder empty and I just run a script that deletes all empty folders. This has the added benefit that the .sqlite3 files are all moved.
MY ISSUE: I have not yet been successful with Robocopy without having to
- explicitly name the path for the destination folder.
Example works:
robocopy "..\..\%FOLDER%" "X:\11Web\gallery-dl\Pixiv - Temp\24517 -" *.* /e /move
Example doesn't work:
robocopy "..\..\%FOLDER%" "..\..\24517 -" *.* /e /move
which after passing a second variable would look more like:
Example doesn't work:
robocopy "..\..\%FOLDER%" "..\..\%FOLDERDESTINATION%" *.* /e /move
nor
- I have no idea how to pass a variable from a folder name that is not known in advance {user[id]} - {user[name]}, but must be searched for within the above root folder.
If there was a way from within the .bat file to
- Declare a variable that matches the current folder {user[id]} (Already done in the below). Example: 24517
and
- And gallery-dl creates the new {user[id]} - {user[name]} and done its business, the .bat find and declare a variable that matches "{user[id]} -".
Example: 24517 - ケースワベ
As such, I will always know the first half of any variable:
{user[id]} -
or in this case
24517 -
Question is can the entire new folder name be searched for based on the known (Example 24517 -), a suitable secondary variable created equating to the new folder name, from only that?
- And is then able to pass this variable to Robocopy in order to successfully move all desired files?
Example:
robocopy "..\..\%FOLDER%" "..\..\%FOLDERDESTINATION%" *.* /e /move
That would be just smashing!
Any and all ideas/assistance are appreciated. Thank you in advance!
Final result after applying successful answer from Stephan
@echo off
setlocal EnableExtensions DisableDelayedExpansion
pushd "%~dp0" || exit /B
move /y "..\Folder2.jpg" "..\Folder.jpg"
for %%I in (..) do set "FOLDER=%%~nxI"
for /f "tokens=1 delims= " %%a in ("%FOLDER%") do set tmpFOLDER=%%a
"C:\Users\AdminS6\gallery-dl\gallery-dl.exe" -d "..\..\." --download-archive "%~dp0GDB.sqlite3" "https://www.pixiv.net/en/users/%FOLDER%/illustrations"
del "..\Folder3.jpg"
if not exist "GDB.sqlite3" move /Y "..\Folder4.jpg" "..\Folder.jpg"
if exist "GDB.sqlite3" del "..\Folder4.jpg" && del "..\Folder.jpg"
if exist "..\*.mp4" md "..\Reels" & move /y "..\*.mp4" "..\Reels\"
if exist "..\*.gif" md "..\GIFs" & move /y "..\*.gif" "..\GIFs\"
if exist "..\*.webp" md "..\WEBPs" & move /y "..\*.webp" "..\WEBPs\"
for /d %%a in ("..\..\%FOLDER% - *") do set "FOLDERDESTINATION=%%a"
rem ECHO %FOLDERDESTINATION%
robocopy "..\..\%FOLDER%" ".\%FOLDERDESTINATION%" *.* /e /move
TIMEOUT /T 1
popd
endlocal
CodePudding user response:
When I understood your question right, this should help:
for /d %%a in ("..\..\%folder% - *") do set "folderdestination=%%a"
(Assumption: there is just one username per %folder%
- else this will get only the last of them)