1.

Solve : need advanced batch file assistance please?

Answer»

Quote from: strokeman on March 04, 2013, 09:04:15 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: strokeman on March 05, 2013, 07:29:39 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"==""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.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"

@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?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 :EOFbugger, 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
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
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.


Discussion

No Comment Found