Quantcast
Channel: Active questions tagged windows - Super User
Viewing all articles
Browse latest Browse all 9224

If not exist (*.*) not working on empty folder (Windows batch)

$
0
0

I don't think I have ever had this happen before. Using these commands:

rem    Check if any anything was downloaded...if not exist "%download_temp%\*.*" goto :fail_messageif exist "%download_temp%\*.*" goto :continue

I can put a pause before those 2 commands and look in the %download_temp% folder and it is definitely empty, I have hidden files and "super hidden" system files set to show in Windows, I am logged in as an Administrator, the folder is definitely empty. I also know the download location being chosen doesn't have the types of files I am trying to download - so I have multiple reasons to know for sure the folder is empty.

Despite that, the above commands still skip to the :continue label instead of where it should, the :fail_message label.

Here's a quirk I noticed - if I change *.* to the file type *.json then everything works as it should, but sometimes it might not be a .json file, hence the use of *.*

I have also tried swapping *.* to just * but get the same effect.

Here's the entire batch file, there's no other goto commands before the ones shown above and I double checked the labels are correct:

cls@echo offmode con: cols=85 lines=40powershell -command "&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=160;$B.height=9999;$W.buffersize=$B;}"cd /d %~dp0rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------rem    This will attempt to download the Live Chat text file from a YouTube video / channel, from a copied clipboard link.rem    rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------title Download Live Chats Before Date (From Clipboard Link)color 0frem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------rem    Define a variable containing a single space characterfor /f %%A in ('"prompt $H &echo on &for %%B in (1) do rem"') do set GAP=%%Arem    Set the input date as variables %year%%month%%day%clsecho.echo.echo    --------------------------------------------------------------------------echo    Please copy the link to a YouTube channels "Video" page to your clipboard.echo.echo    Only Live Chats from BEFORE the date you enter will be downloaded.echo.echo    Please use numbers only, for example type 4 for the month of April, etc.echo    --------------------------------------------------------------------------echo.set /p day="%GAP%   Please type the DAY: "set /p month="%GAP%   Please type the MONTH: "set /p year="%GAP%   Please type the YEAR: "echo.echo    Please wait...rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------rem    Check that yt-dlp is up to date...start /wait /min yt-dlp.exe -Urem    Cleanup from last time if it was updated while the process was running...if exist "yt-dlp.exe.new" del "yt-dlp.exe" & ren "yt-dlp.exe.new" "yt-dlp.exe"rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------rem    Paste url into clipboard.txt...set clipboard_link=%RANDOM%%RANDOM%winclip.exe -p %clipboard_link%.txtrem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------rem    Download Live Chat files to randomly named folder using youtube-dl (using clipboard.txt).rem    Setting a "%RANDOM%" folder here allows multiple downloads to take place at the same time...set download_temp=%RANDOM%%RANDOM%md %download_temp%rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------rem    Download Live Chat to "%download_temp%" folder using yt-dlp (using clipboard.txt).start /wait /min yt-dlp.exe --ignore-errors --skip-download --datebefore %year%%month%%day% --write-sub -o "%download_temp%\%%(upload_date)s - %%(uploader)s - %%(title)s.%%(ext)s" -a %clipboard_link%.txtrem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------rem    Delete the now useless clipboard.txt file...del %clipboard_link%.txtpauserem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------rem    Check if any anything was downloaded...if not exist "%download_temp%\*.*" goto :fail_messageif exist "%download_temp%\*.*" goto :continuerem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:continuerem    Create "NEW\Live Chat" folder.if not exist "..\NEW\Live Chat" md "..\NEW\Live Chat"rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------rem    Remove non-standard characters from file names in the "%download_temp%" folder.xcopy "SpecialChar\*.bat" "%download_temp%" /i /r /v /k /f /c /h /y >nul 2>&1cd /d %download_temp%call rename.bat >nul 2>&1cd /d ..del "%download_temp%\*.bat"rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------echo.echo    Cleaning up Live Chat files to make them readable...echo.echo    Please wait...rem    Clean up the downloaded Live Chat files with powershell.xcopy "ReplaceText\Cleanup_LiveChat.txt" "%download_temp%"  /i /r /v /k /f /c /h /y >nul 2>&1cd /d %download_temp%ren "Cleanup_LiveChat.txt" "Cleanup_LiveChat.cmd"call "Cleanup_LiveChat.cmd" >nul 2>&1del "Cleanup_LiveChat.cmd"cd /d ..rem    ----------------------------------------------------------------------------------------------------------rem    Move the Live Chat files to "NEW\Live Chat"move /y "%download_temp%\*" "..\NEW\Live Chat" >nul 2>&1rd /s /q "%download_temp%\"rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------echo.echo    Finished downloading Live Chats from before date: %day%\%month%\%year%timeout 15 >nulgoto finishedrem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:fail_messageecho.echo    Unfortunately this video/channel did not haveecho    any Live Chats from before date: %day%\%month%\%year%echo.echo    Exiting...timeout 15 >nulgoto finishedrem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:finishedexit

Cheers folks.


Viewing all articles
Browse latest Browse all 9224

Trending Articles