Batch file deleting itself issue
Posted: 10 May 2013 22:56
when run without commandline, AOK, but when run with, alls not well. the routine halts with a batch not found error,
and the batch is, you guessed it, MIA.
how it gets deleted when you'd expect it to have "access denied" attribs while running is anyones guess!
you can test it by running with no %1 for one routine [works], and any %1 for tother.
i must have a missing parenthesis, in a nest, but cant see it.
and the batch is, you guessed it, MIA.
how it gets deleted when you'd expect it to have "access denied" attribs while running is anyones guess!
you can test it by running with no %1 for one routine [works], and any %1 for tother.
i must have a missing parenthesis, in a nest, but cant see it.
Code: Select all
@cls
@ECHO Off
COLOR 0e
if "%~1" == "" goto ProcessNoCmdline
if not "%~1" == "" goto ProcessCmdline
:ProcessNoCmdLine
IF not EXIST NFO2DIR2.TXT (
ECHO Ensure your've read nfo2dir2.txt before you run, Press ^^C if you want to abort.
echo Because WARNING: This will irreversibly, alter disk structure!!!
ping localhost -n 5 >nul
) else (
START /max notepad NFO2DIR2.TXT
)
if not exist *.nfo (
ECHO It appears you haven't run vid. export yet! Aborting with NO changes.
ping localhost -n 5 >nul
exit /B
)
echo.
echo Stacked video files MAY be present, run with
echo commandline next, continuing anyway. .
ping localhost -n 5 >nul
for %%a in (*.nfo) do md "%%~na" & move /y "%%~na.*" "%%~na" & move /y "%%~na-fanart.*" "%%~na" & move /y "%
%~na-poster.*" "%%~na" & move /y "%%~na-thumb.*" "%%~na" & move /y "%%~na-landscape.*" "%%~na" 2 >nul
echo.
echo Please wait. . DON'T INTERRUPT!!
ping localhost -n 5 >nul
if EXIST extrathumbs (
rd /s /q extrathumbs
)
if EXIST extrafanart (
rd /s /q extrafanart
echo.
echo extrafanart and extrathumbs dir. deleted
) ELSE (
echo.
echo extrafanart or extrathumbs dir. not found. . .
:end
cls
echo.
echo The following is a listing of files not yet processed
echo It doesn't show your newly created dir. structure!. . .
echo.
dir /a-d-h
ping localhost -n 5 >nul
echo.
ECHO +------------------------------+
ECHO :XBMC NFO TO DIR Creator V2.50:
ECHO : 2012,2013, by the 'Strokeman':
ECHO +------------------------------+
ECHO.
echo Operation Completed Successfully, you will now have to update Library, After
echo that, please run artwork downloader, then enable extrafanart in chosen skin.
echo.
echo Rogue or orphan stacked files?. . .Run nfo2dir2 with commandline.
ping localhost -n 5 >nul
goto :eof
:ProcessCmdline
@Echo OFF
Color 0b
REM Part of the file name, will be replaced with %~1 to take input from cmd
SET "InFilePartName=%~1"
SET "MaxFiles=%~2" // Default Max Files in sequence is 10
REM Check for user input
IF "%~1" == "" Goto :Error
IF "%~2" == "" SET "MaxFiles=10" // Default max files will be set to 10 if no input was found
Rem The Following is executed when there is input from user
SET "PartName=%InFilePartName:~0,-1%" // This is the name without the last number
SET "PartNum1=%InFilePartName:~-1%" // Remove This Line if The parts always start with number 1
For /L %%A In ( 1 1 %MaxFiles% ) Do (
IF Exist "*%PartName%%%A*" (
CALL :ProcessFiles "%PartName%" "%%A"
)
)
)
REM After It finish it will Display the following and exit
echo.
echo +-----------------------------------------+
Echo Rogue 'n' orphan stacked file mover v1.50
Echo A NFO2DIR2 companion, 2013, 'Strokeman'
Echo +-----------------------------------------+
Echo.
Echo COMPLETED..Directory(s) created and all related files (IF ANY), moved...
GOTO :EOF
Exit
:ProcessFiles
SET "InputName=%~1"
SET "InputNum=%~2"
SETLOCAL EnableDelayedExpansion
For /F "delims=" %%A In (' DIR /B /A:-D "*%InputName%%InputNum%.*" ') Do (
IF Exist "%%A" (
SET "FName=%%~nA"
SET "FNameExt=%%~nxA"
SET "FullFName=%%~dpnxA"
For /F "tokens=1 delims=-.#(" %%z In ( "!FName!" ) Do SET "DirName=%%z"
IF NOT EXIST "!DirName!" MD "!DirName!" >NUL
IF EXIST "!FullFName!" MOVE "!FullFName!" "%%~dpA!DirName!\" >NUL
for %%b in (fanart poster thumb landscape) do (
IF EXIST "%%~dpA!DirName!*-%%b.*" MOVE "%%~dpA!DirName!-*-%%b.*" "%%~dpA!DirName!\" >NUL
)
) Else (
Echo No files found that match. .
ping localhost -n 5 >nul
)
)
gOTO :EOF
:Error
Echo None, or incorrect commandline given. . .exiting with no changes. .
Echo Syntax:clean stackseparator eg. "clean -cd1", "clean disk1"
Echo If orphaned files remain, you may need to manually move.
GOTO :EOF