nested mess

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
stroked
Posts: 20
Joined: 29 Apr 2013 21:48

nested mess

#1 Post by stroked » 10 May 2013 00:47

i tried combining new code to original batch. what i assumed would be a simple condition test for %1 and if true run 1 section, else run nother. nah not that simple!

Code: Select all

@@cls
@ECHO Off
COLOR 0e
   if "%~1" == "" (

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!
        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
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 3 >nul

::@cls
echo.
ECHO          +--------------------------------+
ECHO          :XBMC NFO TO DIR Creator  V2.50. :
ECHO          :(c)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

) ELSE (
   @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
cls
Echo.
Echo +-------------------------------------------+
Echo : Rogue 'n' orphan stacked file mover v1.50 :
Echo : A NFO2DIR2 companion (c)2013, 'Strokeman' :
Echo +-------------------------------------------+
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
   IF EXIST "%%~dpA!DirName!*-fanart.*" MOVE "%%~dpA!DirName!**-fanart.*" "%%~dpA!DirName!\" >NUL
   IF EXIST "%%~dpA!DirName!*-poster.*" MOVE "%%~dpA!DirName!**-poster.*" "%%~dpA!DirName!\" >NUL
   IF EXIST "%%~dpA!DirName!*-thumb.*" MOVE "%%~dpA!DirName!**-thumb.*" "%%~dpA!DirName!\" >NUL
   IF EXIST "%%~dpA!DirName!*-landscape.*" MOVE "%%~dpA!DirName!**-landscape.*" "%%~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
      )

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: nested mess

#2 Post by Endoro » 10 May 2013 02:41

there are several errors in your code. First i would suggest to use "goto" instead of a long "if/else" code block.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: nested mess

#3 Post by abc0502 » 10 May 2013 06:04

I agree with Endoro
You have an else statement without it's if statement
And another one you didn't close

Post Reply