HLP BEGGED!

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

HLP BEGGED!

#1 Post by stroked » 30 Apr 2013 17:36

i have two issue, the 1st it hangs. continuous loop?, need ^c to break.
2nd, when i execute the string now commented out, it wont do the char strip bit. is there a way to format better?
@cls
@ECHO Off
COLOR 1E
ECHO +-----------------------------------------+
ECHO :Rogue 'n' orphan stacked file mover v1.00:
ECHO :A NFO2DIR2 companion (c)2013, 'Strokeman':
ECHO +-----------------------------------------+
ECHO.
if "%1" == "" (goto nocl) else goto bypass
:nocl
echo None, or incorrect commandlines given. . .exiting with no changes. .
echo Syntax:clean stackseparator eg. "clean -cd1", "clean disk1"
echo Rerun for 2nd or 3rd part eg. "clean -cd2", "clean disk2"
echo If orphaned files remain, you may need to manually move
::for %%a in (*%1.*) do md "%%~na" & move /y "%%~na.*" "%%~na" & move /y "%%~na-fanart.*" "%%~na" & move /y "%
%~na-poster.*" "%%~na" & move /y "%%~na-thumb.*" "%%~na"

exit /B

:bypass
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


set end=-%b%
for %%a in (*%1.*) do call :next "%%a"
goto end
:next
set "var=%~n1"
call set "var=%%var:~0,%end%%%"
md "%var%" 2>nul
echo moving %1 to "%var%"
move "%~1" "%var%" 2>nul
ECHO.
echo Completed..directory(s) created and all related files moved...
ping localhost -n 5 >nul
exit

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

Re: HLP BEGGED!

#2 Post by abc0502 » 30 Apr 2013 20:45

Can you explain what it should be doing ?

About the loop problem, all below labels/functions
:bypass
:loop.countChar.2
:end
They all after the exit command and all must end with "GOTO :EOF" command

stroked
Posts: 20
Joined: 29 Apr 2013 21:48

Re: HLP BEGGED!

#3 Post by stroked » 01 May 2013 18:09

fair comment, ill try to be more specific,
lets assume there r 2 files, named test-cd1.avi and test-cd2.avi
" " " the batch file is clean.bat
so we enter 'clean -cd1' at commandline
we want the for/do loop to md called test, thus trim off the four last digits
& into that dir, move test-cd1.avi and repeat with -cd2 as %1
i.e. one of the subr count the chars in the parsed str, and create a dir test
the %1 could be anything, i.e .disk1, -dvd1 etc
thats about all i can say, purpose is sensitive!

ive gotten in a pickle now, its grown bigger than my abilities!. you know i use to know this, but a severe stroke has left me, how shall i say
not just physically impaired but mentally!

now each time it runs, it creates 2 folders, 1 test, and 1 test-cd1. it would appear it's doing 2 iterations now.

@cls
@ECHO Off
COLOR 1E
ECHO +-----------------------------------------+
ECHO :Rogue 'n' orphan stacked file mover v1.00:
ECHO :A NFO2DIR2 companion (c)2013, 'Strokeman':
ECHO +-----------------------------------------+
ECHO.
if "%1" == "" (goto nocl) else goto bypass
:nocl
echo None, or incorrect commandlines given. . .exiting with no changes. .
echo Syntax:clean stackseparator eg. "clean -cd1", "clean disk1"
echo Rerun for 2nd or 3rd part eg. "clean -cd2", "clean disk2"
echo If orphaned files remain, you may need to manually move.
exit /B

:bypass
for %%a in (*%1.*) do md "%%~na" 2>nul
::for %%a in (*%1.*) do move /y "%%~na.*" "%%~na" 2>nul
::for %%a in (*%1.*) do move /y "%%~na-fanart.*" "%%~na" 2>nul
::for %%a in (*%1.*) do move /y "%%~na-poster.*" "%%~na" 2>nul
::for %%a in (*%1.*) do move /y "%%~na-landscape.*" "%%~na" 2>nul
::for %%a in (*%1.*) do move /y "%%~na-thumb.*" "%%~na" 2>nul
echo "%%~na"
echo "%%a"
echo "*%1.*"
pause
set a=%1
setlocal EnableDelayedExpansion
set b=1

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

:cutchars
set end=-%b%
for %%a in (*%1.*) do call :next "%%a"
goto :eof
:next
::set var=
set "var=%~n1"
call set "var=%%var:~0,%end%%%"
md "%var%" 2>nul
echo moving %1 to "%var%"
move /y "%~1" "%var%" 2>nul

:end
@CLS
ECHO.
echo COMPLETED..Directory(s) created and all related files (IF ANY), moved...
::ping localhost -n 5 >nul
goto :eof

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

Re: HLP BEGGED!

#4 Post by Endoro » 01 May 2013 21:24

Could you please put your script between code tags for better reading?

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

Re: HLP BEGGED!

#5 Post by abc0502 » 02 May 2013 00:58

1) is it will always be 2 files in the folder?
2) does these files always have the same name format, ZZZ-cd1.xxx and YYY-cd2.xxx?

and final, from your description, I get that the whole operation is to rename and move to new folder, is that right?

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

Re: HLP BEGGED!

#6 Post by abc0502 » 02 May 2013 01:54

The Following code is based on this:
You have two part of a cd ( 1 & 2 ).
You want to take each one and create a folder of it's name ( without the -cdX.ext ) and move part 1 & 2 to that folder along with the other files belong to it.

Your input must be like this "-cd1",
If you Entered -cd1, it assumes the other cd will be -cd2, if you entered -cd2, the other will be -cd3, and so .

Code: Select all

@Echo OFF
Color 1E

REM Part of the file name, will be replaced with %~1 to take input from cmd
SET "InFilePartName=cd1"

Echo.
Echo +-------------------------------------------+
Echo : Rogue 'n' orphan stacked file mover v1.00 :
Echo : A NFO2DIR2 companion (c)2013, 'Strokeman' :
Echo +-----------------------------------=-------+
Echo.

REM Check for user input
IF "%~1" == "" Goto :Error

Rem The Following is executed when there is input from user
SET "PartName=%InFilePartName:~0,-1%"
SET "PartNum1=%InFilePartName:~-1%"
SET /A PartNum2 = PartNum1 + 1
For %%A In ( %PartNum1% %PartNum2% ) Do (
   CALL :ProcessFiles "%PartName%" "%%A"
   )

REM After It finish it will Display the following and exit
Cls
Echo.
Echo COMPLETED..Directory(s) created and all related files (IF ANY), moved...
Ping localhost -n 5 >nul
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"
      SET "DirName=!FName:~0,-4!"
      IF NOT EXIST "!DirName!" MD "!DirName!" >NUL
      IF EXIST "!FullFName!" MOVE "!FullFName!" "%%~dpA!DirName!\"
      IF EXIST "%%~dpA!DirName!-fanart.*" MOVE "%%~dpA!DirName!-fanart.*" "%%~dpA!DirName!\"
      IF EXIST "%%~dpA!DirName!-poster.*" MOVE "%%~dpA!DirName!-poster.*" "%%~dpA!DirName!\"
      IF EXIST "%%~dpA!DirName!-thumb.*" MOVE "%%~dpA!DirName!-thumb.*" "%%~dpA!DirName!\"
      IF EXIST "%%~dpA!DirName!-landscape.*" MOVE "%%~dpA!DirName!-landscape.*" "%%~dpA!DirName!\"
      ) Else (
         Echo No Files Match
         Pause
   )
)
GOTO :EOF

:Error
Echo None, or incorrect commandlines given. . .exiting with no changes. .
Echo Syntax:clean stackseparator eg. "clean -cd1", "clean disk1"
Echo Rerun for 2nd or 3rd part eg. "clean -cd2", "clean disk2"
Echo If orphaned files remain, you may need to manually move.
GOTO :EOF


Test it on sample files first

stroked
Posts: 20
Joined: 29 Apr 2013 21:48

Re: HLP BEGGED!

#7 Post by stroked » 02 May 2013 16:33

abc0502 wrote:1) is it will always be 2 files in the folder?
2) does these files always have the same name format, ZZZ-cd1.xxx and YYY-cd2.xxx?

and final, from your description, I get that the whole operation is to rename and move to new folder, is that right?


not quite. files will differ, eg ZZZ.disk1.xxx, ZZZ-dvd1.xxx etc, then yyy2, yyy3, etc will follow convention.
the logic is to md named just ZZZ, and move file unmodified into it, as well as ancillary files defined by snippet below into it.
so while the format between the parts is same, %1 will vary. hth, thnx

IF EXIST "!FullFName!" MOVE "!FullFName!" "%%~dpA!DirName!\"
IF EXIST "%%~dpA!DirName!-fanart.*" MOVE "%%~dpA!DirName!-fanart.*" "%%~dpA!DirName!\"
IF EXIST "%%~dpA!DirName!-poster.*" MOVE "%%~dpA!DirName!-poster.*" "%%~dpA!DirName!\"
IF EXIST "%%~dpA!DirName!-thumb.*" MOVE "%%~dpA!DirName!-thumb.*" "%%~dpA!DirName!\"
IF EXIST "%%~dpA!DirName!-landscape.*" MOVE "%%~dpA!DirName!-landscape.*" "%%~dpA!DirName!\"

stroked
Posts: 20
Joined: 29 Apr 2013 21:48

Re: HLP BEGGED!

#8 Post by stroked » 02 May 2013 16:48

abc0502 wrote:The Following code is based on this:
You have two part of a cd ( 1 & 2 ).
You want to take each one and create a folder of it's name ( without the -cdX.ext ) and move part 1 & 2 to that folder along with the other files belong to it..[cut]


thanx for ur effort, works gr8 for *cd1, 2 etc
didnt seem to process *%1.* ancillary files?
plse see my prev post about varying %1.

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

Re: HLP BEGGED!

#9 Post by abc0502 » 03 May 2013 03:13

Ok, so it's not just 2 parts it could be many. the one i made is just processing 2 parts.
But could there be a missing parts like 1,2 and 4 ( no 3 )?

Note: it couldn't take input from you becasue i forgot to change the variable in line 5 to:

Code: Select all

SET "InFilePartName=%~1"
try it again and it will work on any files names beside the -cd1, but it will just handle two parts ONLY.
I will fix that

One more question, will it always start with number 1? like in -cd1, -disk1, etc..

stroked
Posts: 20
Joined: 29 Apr 2013 21:48

Re: HLP BEGGED!

#10 Post by stroked » 03 May 2013 18:07

abc0502 wrote:Ok, so it's not just 2 parts it could be many. the one i made is just processing 2 parts.
But could there be a missing parts like 1,2 and 4 ( no 3 )?

Note: it couldn't take input from you becasue i forgot to change the variable in line 5 to:

Code: Select all

SET "InFilePartName=%~1"
try it again and it will work on any files names beside the -cd1, but it will just handle two parts ONLY.
I will fix that

One more question, will it always start with number 1? like in -cd1, -disk1, etc..

thnx, gr8 minds think alike, tried. but theres issues here SET "DirName=!FName:~0,-4!"
cant i just borrow this subr fm orig script?

set a=%1
setlocal EnableDelayedExpansion
set b=1

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


prob is, i forget how to format b var.! %b%?

nothing written in stone but you can make that assumption about numbering, yes.
if it can process 4 parts, b gr8.

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

Re: HLP BEGGED!

#11 Post by abc0502 » 04 May 2013 06:23

Try This batch, it should be used like this:

Code: Select all

Clean.bat "-disk1" "20"

The "-disk1" : is the part of the file, like "-cd1" etc...
The "20" : is the number of the parts that exist and has the same name part, the default is 10, so if there is more than 10 parts, you must enter the number like "20", if they less you don't have to enter the number and it should be like:

Code: Select all

Clean.bat "-disk1"


Clean.bat [ Updated Code]

Code: Select all

@Echo OFF
Color 1E

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

Echo.
Echo +-------------------------------------------+
Echo : Rogue 'n' orphan stacked file mover v1.00 :
Echo : A NFO2DIR2 companion (c)2013, 'Strokeman' :
Echo +-----------------------------------=-------+
Echo.

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 COMPLETED..Directory(s) created and all related files (IF ANY), moved...
Ping localhost -n 5 >nul
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 Match
         Pause
   )
)
GOTO :EOF

:Error
Echo None, or incorrect commandlines given. . .exiting with no changes. .
Echo Syntax:clean stackseparator eg. "clean -cd1", "clean disk1"
Echo Rerun for 2nd or 3rd part eg. "clean -cd2", "clean disk2"
Echo If orphaned files remain, you may need to manually move.
GOTO :EOF




It should work for any part name as long as it ends with the number ( start number should be 1 ).
Last edited by abc0502 on 05 May 2013 06:58, edited 1 time in total.

stroked
Posts: 20
Joined: 29 Apr 2013 21:48

Re: HLP BEGGED!

#12 Post by stroked » 04 May 2013 16:14

wow, so close now.thanx, hang in there!

issue still with SET "DirName=!FName:~0,-4!"
is assuming %1 will always be 4 chars, what about say -disk1, which is 6?
hence my routine that counted chars parsed.

also this block [processfiles] a nogo
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


have created a blank file called aaa-cd1-fanart.jpg, and one called aaa-cd1.mkv
it mds aaa correctly and moves aaa-cd1.mkv to it. but leaves the jpg where it is?
go on, copy con a few dummy files.

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

Re: HLP BEGGED!

#13 Post by abc0502 » 05 May 2013 06:34

wow, so close now.thanx, hang in there!

issue still with SET "DirName=!FName:~0,-4!"
is assuming %1 will always be 4 chars, what about say -disk1, which is 6?
hence my routine that counted chars parsed.
Oh!, now I see what you mean. This is easy to fix.

Replace

Code: Select all

SET "DirName=!FName:~0,-4!"

With

Code: Select all

For /F "tokens=1 delims=-" %%z In ( "!FName!" ) Do SET "DirName=%%z"



The Other Part fix is like this:
Replace

Code: Select all

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

With

Code: Select all

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


updated Previous code with all these fixes

stroked
Posts: 20
Joined: 29 Apr 2013 21:48

Re: HLP BEGGED!

#14 Post by stroked » 05 May 2013 22:41

perfect, ur the man.
all i did was add 1/2doz probable delimiters, and wildcards to that block.
thanks for your help abc0502

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: HLP BEGGED!

#15 Post by Aacini » 06 May 2013 19:05

You may replace this code:

Code: Select all

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
With this one:

Code: Select all

for %%b in (fanart poster thumb landscape) do (
   IF EXIST "%%~dpA!DirName!*-%%b.*" MOVE "%%~dpA!DirName!-*-%%b.*" "%%~dpA!DirName!\" >NUL
)

Post Reply