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 21447 times)

0 Members and 1 Guest are viewing this topic.

strokeman

  • Guest
need advanced batch file assistance please
« on: January 27, 2013, 10:01:41 PM »
 ??? i want to write a batch file that creates a dir.tmp and processes that to make a directory of the same name LESS the .TBN extension, so it needs to rtrim te string and parse back to %G. Otherwise it will try and create a dir with the same name as the file and crash! you can see the commented out attempt to concatenate.
@cls
SET MyVar=.TBN
@ECHO OFF
COLOR 70
ECHO ------------------------------
ECHO XBMC TBN TO DIR Creator V0.99
ECHO ------------------------------
ECHO be sure you have run a seperate
echo export first, you will need to
echo run a database rebuild next....
pause
COLOR
@echo off
DIR /B *.TBN >DIR.TMP
FOR /F %%G IN (DIR.TMP) DO MD %%G
:Call :TRIM %%MyVar%%
:Echo MyVar=[%%MyVar%%]
:Set MyVar =
:echo %%G
:GoTo :EOF
:TRIM
:Set MyVar=%%*
:GoTo :EOF
MD %%G
:move /Y %%G.* ..%%G

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: need advanced batch file assistance please
« Reply #1 on: January 27, 2013, 11:28:23 PM »
Wait! what is wrong with a directory and file having the same name?
It is not clear what you want to do.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #2 on: January 28, 2013, 03:23:05 AM »
I hope I understood what you were after:

Code: [Select]
@echo off
for %%a in (*.tbn) do md "%%~na"

If you want to move the set of files into the corresponding new folder then this should work:

Code: [Select]
@echo off
for %%a in (*.tbn) do md "%%~na" & move "%%a" "%%~na"

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #3 on: January 28, 2013, 03:27:05 AM »
Wait! what is wrong with a directory and file having the same name?

It's not possibubble, when they are in the same folder, if the folder has the extension too.

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #4 on: January 28, 2013, 10:31:30 PM »

If you want to move the set of files into the corresponding new folder then this should work:

Code: [Select]
@echo off
for %%a in (*.tbn) do md "%%~na" & move "%%a" "%%~na"

assuming %~na is the truncated result, i.e tiger from tiger.tbn, what do i use to copy tiger.* wildcards ? what is %a the tiger.tbn filename?

patio

  • Moderator


  • Genius
  • Maud' Dib
  • Thanked: 1769
    • Yes
  • Experience: Beginner
  • OS: Windows 7
Re: need advanced batch file assistance please
« Reply #5 on: January 28, 2013, 10:53:38 PM »
Possibubble ? ?
" Anyone who goes to a psychiatrist should have his head examined. "

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #6 on: January 29, 2013, 01:52:04 AM »
Possibubble ? ?

Yep.  It's impossibubble.  And the people at the hostipital told me so.

If the file is named file.txt then you can't also have a folder named file.txt in the same location.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #7 on: January 29, 2013, 01:54:52 AM »
assuming %~na is the truncated result, i.e tiger from tiger.tbn, what do i use to copy tiger.* wildcards ? what is %a the tiger.tbn filename?

if you have a file called tiger.tbn and also want to move tiger.txt and tiger.pdf then you can use this:
Code: [Select]
@echo off
for %%a in (*.tbn) do md "%%~na" & move "%%~na.*" "%%~na"

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #8 on: January 29, 2013, 09:51:32 PM »
that did the trick, but more to the point i understand it now

i have been trying to echo a blank line, normally id use ALT+ 032 I Think for a blank char, but this keyboard is made for stroke tetraplegics of which im one

lastly i wish to create a blank file as a marker in an EXIST loop, but without user intervention, ie a >nul, what can i do?, edlin reqs ^Z, for example... :(

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #9 on: January 29, 2013, 11:12:26 PM »
The two ways to test for a folder and a file.  Note the trailing backslash when testing for a folder.

if exist "c:\folder\" type nul >"c:\folder\flagfile.bin"

if exist "c:\autoexec.bat" type nul >"c:\flagfile.bin"

Salmon Trout

  • Guest
Re: need advanced batch file assistance please
« Reply #10 on: January 30, 2013, 03:36:18 AM »
A third way... use the ~a variable modifier with FOR like this

for %%I in ("name") do set AttributeString=%%~aI

"name" is a file or folder name (which must exist!) e.g. "d:\temp\test.txt" or "C:\" or "D:" (no trailing slash needed for folders)

AttributeString is an arbitrary name I chose to hold the result which is a string 9 characters long which has either a lower case letter or a dash in each character position like this: drahscotl. If the attribute is set, the letter is present, if the attribute is unset, there is a dash.

Not all the attributes may be present on all file systems, but they are all possible on NTFS.

for a folder with no attributes set you would have d--------
for a folder which is hidden, system and a junction point or link*, e.g. "My Documents" you see d--hs---l
for a file ready for archiving with no special attributes you would see --a------

the letters mean:

d a directory
r read only
a ready for archiving
h hidden
s system
c compressed
o offline
t temporary
l link/junction point*

Thus:

if "%AttributeString:~0,1%"=="d" then name is a directory
if "%AttributeString:~0,1%"=="-" then name is NOT a directory

* http://comptb.cects.com/2268-overview-to-understanding-hard-links-junction-points-and-symbolic-links-in-windows



« Last Edit: January 30, 2013, 04:06:59 AM by Salmon Trout »

Salmon Trout

  • Guest
Re: need advanced batch file assistance please
« Reply #11 on: January 30, 2013, 04:56:14 AM »
Note: the c (compressed) attribute refers to NTFS compression, not any other type such as Zip.

Salmon Trout

  • Guest
Re: need advanced batch file assistance please
« Reply #12 on: January 30, 2013, 05:46:11 AM »
a fourth way...

dir /ad /b "name">nul 2>&1 && (set isfolder=yes) || (set isfolder=no)



foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #13 on: January 30, 2013, 06:51:16 PM »
Yet another way.  :D


dir "d:\folder"|find ">">nul && echo it's a directory

dir "d:\file.txt"|find ">">nul || echo it's a file

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #14 on: February 01, 2013, 09:00:18 PM »
why is the condition never met?
@cls
@ECHO Off
ECHO +-----------------------------+
ECHO :XBMC NFO TO DIR Creator  V1.0:
ECHO +-----------------------------+
ECHO.

IF NOT EXIST NFO2DIR.TXT (
 ECHO Don't be a bigshot, R.T.F.M Before you run, Press ^^C if you want to abort. .
 ping localhost -n 4 >nul
   ) else (
   START notepad /P NFO2DIR.TXT
   TYPE NUL>"nfo2dir.prn"
   goto bypass
)

if exist nfo2dir.prn (
 echo Printed already. . .
 ping localhost -n 4 >nul
)

if exist nfo2dir.txt (
 START /MAX notepad nfo2dir.txt
)

:bypass
IF NOT EXIST *.NFO (
 ECHO It appears you haven't run vid. export yet!
 ping localhost -n 4 >nul
 exit
)

if not exist "nfo2dir.done" (
 type nul >"nfo2dir.done"
   ) else (                                                                                         
   ECHO You have processed already
   ping localhost -n 4 >nul
   exit
)

echo Please wait. . DON'T INTERUPT!!
ping localhost -n 4 >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. . .
)

dir /s ::do directory list including subdirs.
@cls
echo Operation Completed Successfully.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #15 on: February 01, 2013, 10:16:26 PM »
It will only run if these two conditions are true:

IF NOT EXIST NFO2DIR.TXT
if exist nfo2dir.prn

because if NFO2DIR.TXT exists it will goto :bypass

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #16 on: February 23, 2013, 09:01:53 PM »
can anyone see why <moviename>-CD1 would not be processed pls?

@cls
@ECHO Off
ECHO +-----------------------------+
ECHO :XBMC NFO TO DIR Creator  V1.1:
ECHO +-----------------------------+
ECHO.

IF not EXIST NFO2DIR.TXT (
     ECHO Don't be a bigshot, R.T.F.M Before you run, Press ^^C if you want to abort. .
   ping localhost -n 4 >nul
 ) else (
 START /max notepad NFO2DIR.TXT
)
   
IF NOT EXIST *.NFO (
 ECHO It appears you haven't run vid. export yet!
 ping localhost -n 4 >nul
 exit
)

if not exist "nfo2dir.done" (
 type nul >"nfo2dir.done"
 attrib +h +r nfo2dir.done >nul
   ) else (                                                                                         
   ECHO You have processed already
   ping localhost -n 4 >nul
   exit
)

echo Please wait. . DON'T INTERUPT!!
ping localhost -n 4 >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. . .
)

dir /s ::do directory list including subdirs.
@cls
echo Operation Completed Successfully.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #17 on: February 24, 2013, 02:21:29 AM »
There isn't enough information - try putting echo and pause commands to see which loop is causing it to be skipped.

Salmon Trout

  • Guest
Re: need advanced batch file assistance please
« Reply #18 on: February 24, 2013, 02:54:41 AM »
Quote
dir /s ::do directory list including subdirs.

Probably not (directly) related to the problem, but this will not do what you appear to hope it will. By the way, this is how you spell interrupt. And do we need to see "R.T.F.M"?






strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #19 on: February 25, 2013, 02:57:12 PM »
yes, bit abrupt, but so are the irreversible disk changes that are made, so makes sure user has read and understands that. well  spotted, i do know how to spell, but being disabled and wheelchair bound after a stroke, left me with one partially working limb, and the non dominant one at that, so i stab away and many typos creep in.

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #20 on: February 25, 2013, 03:02:15 PM »
There isn't enough information - try putting echo and pause commands to see which loop is causing it to be skipped.

have broken it down, and created dummy files. it does work. there was no corresponding nfo file, twas all! 8)

Salmon Trout

  • Guest
Re: need advanced batch file assistance please
« Reply #21 on: February 25, 2013, 03:34:48 PM »
yes, bit abrupt

The 'F' in RTFM stands for a profane word. This is a site accessed by people of all ages.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #22 on: February 25, 2013, 04:20:50 PM »
'Read the fine manual'?  I have no issues with that... ;)

It's good to see you using your skills strokeman, and making the best of a hard situation.  My bro had a stroke too.

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #23 on: February 25, 2013, 09:53:14 PM »
The 'F' in RTFM stands for a profane word. This is a site accessed by people of all ages.

FREE is profane?, chillax, those that know what it stands for, might be bemused, those that don't, i.e. kids, still don't. one thing my accident taught me is  'to live every day like its your last, you never know it just might be" smell the roses fella..
« Last Edit: February 25, 2013, 10:28:55 PM by strokeman »

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #24 on: February 25, 2013, 10:47:52 PM »
so i want 2 parse %1, the commandline var that would be -cd1 in this case, how to trim in this case 4 chars?

for %%a in (*%%1.*) do md "%%~na-count[%%1)" & move "%%~na.*" "%%~na" of course know this wont work, just thinking out loud!

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #25 on: February 26, 2013, 12:37:56 AM »
so i want 2 parse %1, the commandline var that would be -cd1 in this case, how to trim in this case 4 chars?

This will give you the last 4 characters:

Code: [Select]
set "var=%~1"
set "num=%var:~-4%"
echo "%num%"
pause

This will give you the name, without the last four characters.

Code: [Select]
set "var=%~1"
set "name=%var:~0,-4%"
echo "%name%"
pause

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #26 on: February 26, 2013, 10:13:54 PM »
so as there doesn't seem to be a string type funct that determines the length of %1 in chars, ill parse 2 params like -cd1 4, .disk1 6 etc.

here i get lost, for the dummyfile test-cd1.avi, id expect %name% to be test. its not. how to implement in the for/do loop?
this is what i have so far

@ECHO OFF
@CLS
set "var=%~1"
set "num=%var:~-%2%"
echo num="%num%"
pause
set "name=%var:~0,-%2%"
echo name="%name%"
pause
for %%a in (*%1.*) do md "%%~na" & move "%%~na.*" "%%~na"

for the cd1 4 test, it returns
%num%=%var:~-4 when id expect -4
%name%=%var:~0,-4 when id expect test

what am i not seeing foxidrive man?

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #27 on: February 27, 2013, 01:04:20 AM »
See if this gives you what you want.  Your issue was having %2 there.

JFTR It helps a lot to describe what you want to do and supply some filenames.  There are other methods to parse filenames and the best way depends on what you need and what the makeup of the filenames are.

Code: [Select]
@ECHO OFF
set "var=%~n1"
echo filename is "%~n1"
set "num=%var:~-2%"
echo num="%num%"
set "name=%var:~0,-2%"
echo name="%name%"
pause

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #28 on: February 27, 2013, 07:31:43 PM »
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 test.bat
so we enter test -cd1 4 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 test-cd2.avi
the %1 an %2 vars could be anything, i.e .disk1 6, -dvd1 5 etc
i was expecting '-4' for %num%, and %name% = 'test'
hth

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: need advanced batch file assistance please
« Reply #29 on: February 27, 2013, 08:43:46 PM »
if they are all formatted 'test-something', you can use
Code: [Select]
for /f "tokens=1,2 delims=-" %%A in ('dir /b') do (
if not "%%A"=="%~n0" (
if not exist %%A md %%A
move /y "%%A-%%B" "%%A\%%A-%%B"
)
)
but you may have to change the delim if they don't have '-'.

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 #30 on: February 27, 2013, 09:24:24 PM »
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 test.bat
so we enter test -cd1 4 at commandline

The batch file is called test.bat
So you entered test -cd1 4

But you are not passing the filename - how does the batch file know which filename(s) to operate on?

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #31 on: February 28, 2013, 07:33:51 PM »
it changes each iteration, its from the for/do loop which processes the wildcard based on %1, in this case *-cd1.*. i guess im wanting -cd1 removed from the current file. the %2 giving the number of chars to remove, tho would much rather have a function that determines this from %1.

so its what to do with

for %%a in (*%1.*) do md "%%~na" & move "%%~na.*" "%%~na"

clear as mud?

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #32 on: February 28, 2013, 10:40:29 PM »
If you are trying to sort groups of files but there are numerous suffixes on them, then you can do it in batches semi-manually.

This should take avi files ending in -cd1, -cd2, -cd3, -cd4 (or -cd with any next character) and move them into respective folders, named from the filename without the ending 4 characters.


Code: [Select]
@echo off
set end=-4
for %%a in (*-cd?.avi) do call :next "%%a"
echo done
pause
goto :EOF
:next
set "var=%~n1"
call set "var=%%var:~0,%end%%%"
md "%var%" 2>nul
echo moving %1 to "%var%"
move "%~1" "%var%" >nul


repeat with different filespecs and the appropriate number for the length of the suffix.

Filenames with % and ^ in them could cause issues.

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #33 on: March 01, 2013, 07:19:21 PM »
u make it look easy!, im struggling to understand it
works fine putting in each variation on commandline
now if only i could get it todo 3 increments, without changing %1 and running it again.
how do we add 1 to %%a?, is it even poss.?, what about doing stuff to %2?

@echo off
set end=-%2
for %%a in (*%1.*) do call :next "%%a"
goto :EOF
:next
set "var=%~n1"<---w t f is n1?
call set "var=%%var:~0,%end%%%"
md "%var%" 2>nul <--- w t f does the 2 do?
move "%~1" "%var%" >nul

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #34 on: March 01, 2013, 10:19:19 PM »
now if only i could get it todo 3 increments, without changing %1 and running it again.

We are guessing what you are doing.  It's hard to give advice without knowing the task.


set "var=%~n1"<---w t f is n1?

Read the help for for /? and you'll find it at the end.

md "%var%" 2>nul <--- w t f does the 2 do?

In this case it eliminates a message in STDERR about the folder already existing.   The error message goes to NUL when the folder already exists.


Salmon Trout

  • Guest
Re: need advanced batch file assistance please
« Reply #35 on: March 02, 2013, 02:46:30 AM »

md "%var%" 2>nul <--- w t f does the 2 do?

In this case it eliminates a message in STDERR about the folder already existing.   The error message goes to NUL when the folder already exists.

My way of getting around that is to do an IF EXIST test e.g. if not exist logfolder md logfolder

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: need advanced batch file assistance please
« Reply #36 on: March 02, 2013, 06:44:27 AM »
My way of getting around that is to do an IF EXIST test e.g. if not exist logfolder md logfolder

That's the traditional and effective and sensible way - I'm lazy in some respects and go for the 2>nul these days.

I do the same with del filename.txt 2>nul

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #37 on: March 02, 2013, 02:44:45 PM »
can live with your solution, but surely there's a function about to count the chars in %1 instead of %2?

eg commandlines

-cd1 4
.disk1 6

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: need advanced batch file assistance please
« Reply #38 on: March 02, 2013, 06:48:48 PM »
Code: [Select]
@echo off
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 %2 %b%
pause

will count the number of characters in argument 1 (%1). It's kinda long, but works relatively well.

Code: [Select]

C:\Users\Lemonilla\Documents\bat>call countCharInArg2.bat thisIs16CharLong 1
thisIs16CharLong                16
Press any key to continue . . .

C:\Users\Lemonilla\Documents\bat>


EDIT: misread your post, fixed code to count from arg 1 and not arg 2.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #39 on: March 04, 2013, 07:50:32 PM »
I know this doesn't work, how can i pass no .nfo file, AND no commandline given?

IF NOT EXIST *.NFO & z=%1z (
  ECHO It appears you haven't run vid. export yet!
  ping localhost -n 5 >nul
  exit /B
)

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: need advanced batch file assistance please
« Reply #40 on: March 04, 2013, 08:10:51 PM »
Code: [Select]
if not exist *.nfo (
    if "%1z"=="z" (
        ECHO It appears you haven't run vid. export yet!
        ping localhost -n 5 >nul
        exit /B
    )
)
not sure what you mean by =z, but this should only activate if both statements return true.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #41 on: March 04, 2013, 08:52:36 PM »
its my solution and likely the wrong 1. This is TRUE only when no %1 exists, ie 'z'=='z'. what is right way IF exist %1==""?
aaahhh, wouldnt have thought of nesting loops. thanx

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #42 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
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

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: need advanced batch file assistance please
« Reply #43 on: March 05, 2013, 05:02:19 AM »
is there a reason that it uses %1z and not %1 in the if statement? The only thing I can think of for z would be %:~z1 which is file size, and I don't think that's what you were looking for.  the if statement would only work if "%1%"=="", or is undefined.

oh, and if %1 is more than one word, then you need to put quotes around it in all your statements, otherwise some will not run properly.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

strokeman

  • Guest
Re: need advanced batch file assistance please
« Reply #44 on: March 05, 2013, 07:29:39 PM »
is there a reason that it uses %1z and not %1 in the if statement? The only thing I can think of for z would be %:~z1 which is file size, and I don't think that's what you were looking for.  the if statement would only work if "%1%"=="", or is undefined.

oh, and if %1 is more than one word, then you need to put quotes around it in all your statements, otherwise some will not run properly.

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.

just wanted foxidrive and lemonilla to double check their respective code. post insertion they worked fine, so must be a syntaxy/typo thing going on.

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.