Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: need advanced batch file assistance please  (Read 21429 times)

0 Members and 2 Guests are viewing this topic.

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: need advanced batch file assistance please
« Reply #45 on: March 05, 2013, 07:42:17 PM »
is fine but not processing %1, whats wrong?

@cls
@ECHO Off
ECHO +-----------------------------+
ECHO :XBMC NFO TO DIR Creator  V2.0:
ECHO +-----------------------------+
ECHO.

IF not EXIST NFO2DIR.TXT (
     ECHO Ensure yourv'e read nfo2dir.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 NFO2DIR.TXT
)
   
if not exist *.nfo (
    if "%1z"=="z" (
        ECHO It appears you haven't run vid. export yet!
        ping localhost -n 5 >nul
        exit /B
    )
)
echo Please wait. . DON'T INTERRUPT!!
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"

if EXIST extrathumbs (
 rd /s /q extrathumbs
)

if EXIST extrafanart (
 rd /s /q extrafanart   
 echo extrafanart and extrathumbs dir. deleted
   ) ELSE (
   echo extrafanart or extrathumbs dir. not found. . .
)

if not x==%1x goto end  <-- may want to change this to 'if "x"=="%1x" goto end' that way, if %1 is more than one word, it wont get messed up
set a=%1
setlocal EnableDelayedExpansion
set b=1
:loop.countChar.2
call set c=%%a:~!b!,1%%
if "%c%"=="" goto end
set /a b+=1
goto loop.countChar.2
:end
echo Stacked files may exist, no switches given, read manual
ping localhost -n 5 >nul
dir /p
exit /b

set end=-%b%
for %%a in (*%1.*) do call :next "%%a"
goto :EOF
:next
set "var=%~n1"
call set "var=%%var:~0,%end%%%"
md "%var%" 2>nul
move "%~1" "%var%" >nul

@cls
echo Operation Completed Successfully.
ping localhost -n 5 >nul

That's the only thing I can see, but there may be more that i'm missing. Hard to test without the files.  If it still doesn't work, try dropping pause's between the chunks of code to find which one is causing the error.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #46 on: March 05, 2013, 09:54:57 PM »
when theres not a %1 given, ie its blank z or x,y,z whatever you give it, z==z, so a TRUE condition is met.

It will fail with quoted terms.    That technique from MSDOS days should be replaced with this in windows:

Code: [Select]
if "%~1"==""

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: need advanced batch file assistance please
« Reply #47 on: March 06, 2013, 04:42:42 AM »
Thanks for the correction foxidrive, I knew it looked funny, but couldn't figure out why.

out of curiosity, why would it fail with quotes?  Does it have something to do with not replacing %1? It seemed to work when I used %a% in cmd.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #48 on: March 06, 2013, 05:08:38 AM »
In this instance the %1 will contain quotes when long filename elements are used in %1.

if "%1z"=="z"

So that line will expand to this which is a mess and the long filename elements like spaces and & will cause an error message:

if ""my file.txt"z"=="z"


strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #49 on: March 16, 2013, 11:09:34 PM »
@cls
::@ECHO Off
COLOR 1F
ECHO          +--------------------------------+
ECHO          :XBMC NFO TO DIR Creator  V2.00. :
ECHO          :(c)2012,2013, by the 'Strokeman':
ECHO          +--------------------------------+
ECHO.

IF not EXIST NFO2DIR.TXT (
     ECHO Ensure your've read nfo2dir.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 NFO2DIR.TXT
)
goto miss   

if not exist *.nfo (
        echo.
   ECHO It appears you haven't run vid. export yet!
        ping localhost -n 5 >nul
        exit /B
)
:miss
if "%~1"=="" (
echo.
echo Stacked video files MAY be present, no
echo commandlines given, continuing anyway. .
ping localhost -n 5 >nul
)

echo.               
echo Please wait. . DON'T INTERRUPT!!
ping localhost -n 5 >nul

for %%a in (*.NFO) do md "%%~na" & move /y "%%~na.*" "%%~na" >nul

if exist (*-fanart.*) (
 for %%a in (*.) do (
  move /y "%%~na-fanart.*" "%%~na" >nul
 )
  )

if exist (*-poster.*) (
 for %%a in (*.) do (
  move /y "%%~na-poster.*" "%%~na" > nul
 )
  )

if exist (*-landscape.*) (
 for %%a in (*.) do (
  move /y "%%~na-landscape.*" "%%~na" >nul
 )
  )

if exist (*-thumb.*) (
 for %%a in (*.) do (
  move /y "%%~na-thumb.*" "%%~na" >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. . .
)

set a=%1
setlocal EnableDelayedExpansion
set b=1
:loop.countChar.2
call set c=%%a:~!b!,1%%
if "%c%"=="" goto end
set /a b+=1
goto loop.countChar.2

:end
echo.
echo The following is a listing of files not yet processed
echo it dosent show your newly created dir. structure!. . .
echo.
dir /a-d-h
ping localhost -n 3 >nul
goto :eof

set end=-%b%
for %%a in (*%1.*) do call :next "%%a"

goto end
if not "%~1"=="" (
:next
set "var=%~n1"
call set "var=%%var:~0,%end%%%"
md "%var%" 2>nul
echo moving %1 to "%var%"
move "%~1" "%var%" >nul
)

:skip
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.
ping localhost -n 5 >nul

i dont get it, have looked at it a million times. if i put in a %1 its fine, but with no commandline it gets stuck in the red section, incrementing to affinity, till i ^c it?

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #50 on: March 16, 2013, 11:44:03 PM »
Looking only at the red bit:

Code: [Select]
goto end
:next
set "var=%~n1"
call set "var=%%var:~0,%end%%%"
md "%var%" 2>nul
echo moving %1 to "%var%"
move "%~1" "%var%" >nul
goto :EOF

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #51 on: March 17, 2013, 05:21:21 PM »
bugger, hl the wrong section, sorry!

set a=%1
setlocal EnableDelayedExpansion
set b=1
:loop.countChar.2
call set c=%%a:~!b!,1%%
if "%c%"=="" goto end
set /a b+=1
goto loop.countChar.2
goto :EOF

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #52 on: March 17, 2013, 10:10:29 PM »
The characters % and ^ in filenames might cause problems.

Code: [Select]
@echo off
set "a=%~1"
set b=0
:loop.countChar.2
call set "c=%%a:~%b%,1%%"
if "%c%"=="" goto :end
set /a b+=1
goto loop.countChar.2

:end
echo %b%
pause

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #53 on: March 17, 2013, 10:46:08 PM »
i just wrapped it in if not exist "%~1" (...code....). so it skips that section if no %1 specified, but thats just avoiding the prob, so will try your way.

thanks so far, you guys rock! theres some issues still, but have other 'work', so will have 2 shelve it for now  :'(. but ill be back.