Working with a mapped directory

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ipso
Posts: 3
Joined: 15 Dec 2014 12:06

Working with a mapped directory

#1 Post by ipso » 15 Dec 2014 12:23

Hi guys,

I'm new working with batch files. I made this script but it only works propperly when is running in a local resource. When it points to a network mapped directory doesn't catch the list in the same order.

See script below:

Code: Select all

::@echo off
setlocal enabledelayedexpansion
cd /D %~dp0
cd A
set i=0
for %%a in (*.*) do set /A i+=1 & set alpha[!i!]=%%a & set gamma[!i!]=%%~na
cd ..
cd B
set i=0
for %%b in (*.*) do set /A i+=1 & set beta[!i!]=%%b
cd ..
set n=%i%
for /L %%i in (1,1,%n%) do "Z:\mkvtoolnix\mkvmerge.exe" -o "output\!gamma[%%i]!.mkv" --track-name 1:dts "A\!alpha[%%i]!" --no-video --sync 0:860,65596/65599 --language 0:Spanish --default-track 0 --track-name 0:ac3 --no-chapters --no-global-tags "B\!beta[%%i]!"
pause


Please some help!! Thx in advance

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Working with a mapped directory

#2 Post by foxidrive » 15 Dec 2014 14:31

Can you explain how it fails?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Working with a mapped directory

#3 Post by Squashman » 15 Dec 2014 14:40

You are saying that the directory listing is not outputting the same for the two different FOR commands?
If so then just try forcing it to do so.

Code: Select all

for /f "delims=" %%a in ('dir /a-d /b /on *.*') do set /A i+=1 & set alpha[!i!]=%%a & set gamma[!i!]=%%~na
for /F "delims=" %%b in ('dir /a-d /b /on *.*') do set /A i+=1 & set beta[!i!]=%%b

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Working with a mapped directory

#4 Post by foxidrive » 15 Dec 2014 14:43

The network drive might not be NTFS and so isn't sorting properly - you may be right there Squashman.

ipso
Posts: 3
Joined: 15 Dec 2014 12:06

Re: Working with a mapped directory

#5 Post by ipso » 15 Dec 2014 14:58

Thanks for reply!

Example running in local:

Code: Select all

D:\MKV Merge>setlocal enabledelayedexpansion

D:\MKV Merge>cd /D D:\MKV Merge\

D:\MKV Merge>cd A

D:\MKV Merge\A>set i=0

D:\MKV Merge\A>for %a in (*.*) do set /A i+=1   & set alpha[!i!]=%a   & set gamm
a[!i!]=%~na

D:\MKV Merge\A>set /A i+=1   & set alpha[!i!]=S6E10-Chain of Command Part 1.mkv
  & set gamma[!i!]=S6E10-Chain of Command Part 1

D:\MKV Merge\A>set /A i+=1   & set alpha[!i!]=S6E11-Chain of Command Part 2.mkv
  & set gamma[!i!]=S6E11-Chain of Command Part 2

D:\MKV Merge\A>set /A i+=1   & set alpha[!i!]=S6E12-Ship in a Bottle.mkv   & set
 gamma[!i!]=S6E12-Ship in a Bottle

D:\MKV Merge\A>set /A i+=1   & set alpha[!i!]=S6E13-Aquiel.mkv   & set gamma[!i!
]=S6E13-Aquiel

D:\MKV Merge\A>set /A i+=1   & set alpha[!i!]=S6E14-Face of the Enemy.mkv   & se
t gamma[!i!]=S6E14-Face of the Enemy

D:\MKV Merge\A>set /A i+=1   & set alpha[!i!]=S6E15-Tapestry.mkv   & set gamma[!
i!]=S6E15-Tapestry

D:\MKV Merge\A>cd ..

D:\MKV Merge>cd B

D:\MKV Merge\B>set i=0

D:\MKV Merge\B>for %b in (*.*) do set /A i+=1   & set beta[!i!]=%b

D:\MKV Merge\B>set /A i+=1   & set beta[!i!]=10 TNG S7D3 Chain of command part 1
.mp3

D:\MKV Merge\B>set /A i+=1   & set beta[!i!]=11 TNG S7D3 Chain of command part 2
.mp3

D:\MKV Merge\B>set /A i+=1   & set beta[!i!]=12 TNG S7D3 Ship in a bottle.mp3

D:\MKV Merge\B>set /A i+=1   & set beta[!i!]=13 TNG S7D4 Aquiel.mp3

D:\MKV Merge\B>set /A i+=1   & set beta[!i!]=14 TNG S7D4 Face of the enemy.mp3

D:\MKV Merge\B>set /A i+=1   & set beta[!i!]=15 TNG S7D4 Tapestry.mp3

D:\MKV Merge\B>cd ..

D:\MKV Merge>set n=6

D:\MKV Merge>for /L %i in (1 1 6) do "D:\MKV Merge\mkvtoolnix\mkvmerge.exe" -o "
output\!gamma[%i]!.mkv" --track-name 1:dts "A\!alpha[%i]!" --no-video --sync 0:8
10,65596/65400 --language 0:Spanish --default-track 0 --track-name 0:ac3 --no-ch
apters --no-global-tags "B\!beta[%i]!"

D:\MKV Merge>"D:\MKV Merge\mkvtoolnix\mkvmerge.exe" -o "output\!gamma[1]!.mkv" -
-track-name 1:dts "A\!alpha[1]!" --no-video --sync 0:810,65596/65400 --language
0:Spanish --default-track 0 --track-name 0:ac3 --no-chapters --no-global-tags "B
\!beta[1]!"
mkvmerge v7.3.0 ('Nouages') 64bit built on Oct 22 2014 18:53:34
'A\S6E10-Chain of Command Part 1.mkv ': Using the demultiplexer for the format '
Matroska'.
'B\10 TNG S7D3 Chain of command part 1.mp3': Using the demultiplexer for the for
mat 'MP2/MP3'.
Warning: 'B\10 TNG S7D3 Chain of command part 1.mp3': Skipping 45 bytes at the b
eginning (no valid MP3 header found).
'A\S6E10-Chain of Command Part 1.mkv ' track 0: Using the output module for the
format 'AVC/h.264'.
'A\S6E10-Chain of Command Part 1.mkv ' track 1: Using the output module for the
format 'DTS'.
'A\S6E10-Chain of Command Part 1.mkv ' track 2: Using the output module for the
format 'PGS'.
'A\S6E10-Chain of Command Part 1.mkv ' track 3: Using the output module for the
format 'PGS'.
'A\S6E10-Chain of Command Part 1.mkv ' track 4: Using the output module for the
format 'PGS'.
'A\S6E10-Chain of Command Part 1.mkv ' track 5: Using the output module for the
format 'PGS'.
'A\S6E10-Chain of Command Part 1.mkv ' track 6: Using the output module for the
format 'PGS'.
'A\S6E10-Chain of Command Part 1.mkv ' track 7: Using the output module for the
format 'PGS'.
'A\S6E10-Chain of Command Part 1.mkv ' track 8: Using the output module for the
format 'PGS'.
'A\S6E10-Chain of Command Part 1.mkv ' track 9: Using the output module for the
format 'PGS'.
'A\S6E10-Chain of Command Part 1.mkv ' track 10: Using the output module for the
 format 'PGS'.
'A\S6E10-Chain of Command Part 1.mkv ' track 11: Using the output module for the
 format 'PGS'.
'A\S6E10-Chain of Command Part 1.mkv ' track 12: Using the output module for the
 format 'PGS'.
'B\10 TNG S7D3 Chain of command part 1.mp3' track 0: Using the output module for
 the format 'MP3'.
The file 'output\S6E10-Chain of Command Part 1.mkv' has been opened for writing.

Progress: 100%


Example running in the mapped drive:

Code: Select all

Z:\_Box\MKV Merge>setlocal enabledelayedexpansion

Z:\_Box\MKV Merge>cd /D Z:\_Box\MKV Merge\

Z:\_Box\MKV Merge>cd A

Z:\_Box\MKV Merge\A>set i=0

Z:\_Box\MKV Merge\A>for %a in (*.*) do set /A i+=1   & set alpha[!i!]=%a   & set
 gamma[!i!]=%~na

Z:\_Box\MKV Merge\A>set /A i+=1   & set alpha[!i!]=S6E14-Face of the Enemy.mkv
 & set gamma[!i!]=S6E14-Face of the Enemy

Z:\_Box\MKV Merge\A>set /A i+=1   & set alpha[!i!]=S6E15-Tapestry.mkv   & set ga
mma[!i!]=S6E15-Tapestry

Z:\_Box\MKV Merge\A>set /A i+=1   & set alpha[!i!]=S6E10-Chain of Command Part 1
.mkv   & set gamma[!i!]=S6E10-Chain of Command Part 1

Z:\_Box\MKV Merge\A>set /A i+=1   & set alpha[!i!]=S6E11-Chain of Command Part 2
.mkv   & set gamma[!i!]=S6E11-Chain of Command Part 2

Z:\_Box\MKV Merge\A>set /A i+=1   & set alpha[!i!]=S6E12-Ship in a Bottle.mkv
& set gamma[!i!]=S6E12-Ship in a Bottle

Z:\_Box\MKV Merge\A>set /A i+=1   & set alpha[!i!]=S6E13-Aquiel.mkv   & set gamm
a[!i!]=S6E13-Aquiel

Z:\_Box\MKV Merge\A>cd ..

Z:\_Box\MKV Merge>cd B

Z:\_Box\MKV Merge\B>set i=0

Z:\_Box\MKV Merge\B>for %b in (*.*) do set /A i+=1   & set beta[!i!]=%b

Z:\_Box\MKV Merge\B>set /A i+=1   & set beta[!i!]=15 TNG S7D4 Tapestry.mp3

Z:\_Box\MKV Merge\B>set /A i+=1   & set beta[!i!]=10 TNG S7D3 Chain of command p
art 1.mp3

Z:\_Box\MKV Merge\B>set /A i+=1   & set beta[!i!]=11 TNG S7D3 Chain of command p
art 2.mp3

Z:\_Box\MKV Merge\B>set /A i+=1   & set beta[!i!]=12 TNG S7D3 Ship in a bottle.m
p3

Z:\_Box\MKV Merge\B>set /A i+=1   & set beta[!i!]=13 TNG S7D4 Aquiel.mp3

Z:\_Box\MKV Merge\B>set /A i+=1   & set beta[!i!]=14 TNG S7D4 Face of the enemy.
mp3

Z:\_Box\MKV Merge\B>cd ..

Z:\_Box\MKV Merge>set n=6

Z:\_Box\MKV Merge>for /L %i in (1 1 6) do "Z:\_Box\MKV Merge\mkvtoolnix\mkvmerge
.exe" -o "output\!gamma[%i]!.mkv" --track-name 1:dts "A\!alpha[%i]!" --no-video
--sync 0:860,65596/65599 --language 0:Spanish --default-track 0 --track-name 0:a
c3 --no-chapters --no-global-tags "B\!beta[%i]!"

Z:\_Box\MKV Merge>"Z:\_Box\MKV Merge\mkvtoolnix\mkvmerge.exe" -o "output\!gamma[
1]!.mkv" --track-name 1:dts "A\!alpha[1]!" --no-video --sync 0:860,65596/65599 -
-language 0:Spanish --default-track 0 --track-name 0:ac3 --no-chapters --no-glob
al-tags "B\!beta[1]!"
mkvmerge v7.3.0 ('Nouages') 64bit built on Oct 22 2014 18:53:34
'A\S6E14-Face of the Enemy.mkv ': Using the demultiplexer for the format 'Matros
ka'.
'B\15 TNG S7D4 Tapestry.mp3': Using the demultiplexer for the format 'MP2/MP3'.
Warning: 'B\15 TNG S7D4 Tapestry.mp3': Skipping 45 bytes at the beginning (no va
lid MP3 header found).
'A\S6E14-Face of the Enemy.mkv ' track 0: Using the output module for the format
 'AVC/h.264'.
'A\S6E14-Face of the Enemy.mkv ' track 1: Using the output module for the format
 'DTS'.
'A\S6E14-Face of the Enemy.mkv ' track 2: Using the output module for the format
 'PGS'.
'A\S6E14-Face of the Enemy.mkv ' track 3: Using the output module for the format
 'PGS'.
'A\S6E14-Face of the Enemy.mkv ' track 4: Using the output module for the format
 'PGS'.
'A\S6E14-Face of the Enemy.mkv ' track 5: Using the output module for the format
 'PGS'.
'A\S6E14-Face of the Enemy.mkv ' track 6: Using the output module for the format
 'PGS'.
'A\S6E14-Face of the Enemy.mkv ' track 7: Using the output module for the format
 'PGS'.
'A\S6E14-Face of the Enemy.mkv ' track 8: Using the output module for the format
 'PGS'.
'A\S6E14-Face of the Enemy.mkv ' track 9: Using the output module for the format
 'PGS'.
'A\S6E14-Face of the Enemy.mkv ' track 10: Using the output module for the forma
t 'PGS'.
'A\S6E14-Face of the Enemy.mkv ' track 11: Using the output module for the forma
t 'PGS'.
'A\S6E14-Face of the Enemy.mkv ' track 12: Using the output module for the forma
t 'PGS'.
'B\15 TNG S7D4 Tapestry.mp3' track 0: Using the output module for the format 'MP
3'.
The file 'output\S6E14-Face of the Enemy.mkv' has been opened for writing.
Progress: 42%


I'm trying to merge several matroska with their respective audio tracks. When I run it locally the order is alphabetical, all ok! But running in the mapped drive nothing... seems to follow a completely random order...

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Working with a mapped directory

#6 Post by foxidrive » 15 Dec 2014 15:08

As above, the network drive may be a FAT formatted drive which returns the directory entries in an unsorted list.

ipso
Posts: 3
Joined: 15 Dec 2014 12:06

Re: Working with a mapped directory

#7 Post by ipso » 15 Dec 2014 15:14

Squashman wrote:You are saying that the directory listing is not outputting the same for the two different FOR commands?
If so then just try forcing it to do so.

Code: Select all

for /f "delims=" %%a in ('dir /a-d /b /on *.*') do set /A i+=1 & set alpha[!i!]=%%a & set gamma[!i!]=%%~na
for /F "delims=" %%b in ('dir /a-d /b /on *.*') do set /A i+=1 & set beta[!i!]=%%b


Thank you very much Squashman! Now working as expected :mrgreen:

Furthermore, correct the unit isn't NTFS, had no idea that this would affect :oops:

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Working with a mapped directory

#8 Post by Squashman » 15 Dec 2014 16:13

You know you could have probably just done a simple DIR or FOR command at the cmd prompt instead of showing us all the code output. Just saying.

ALbino
Posts: 29
Joined: 23 Oct 2014 19:27

Re: Working with a mapped directory

#9 Post by ALbino » 15 Dec 2014 22:43

@echo off

It's your friend :P

Post Reply