Home > Net >  Batch command to select multiple file and output it as single line
Batch command to select multiple file and output it as single line

Time:03-24

I tried to find a many way to finish this but still no hope ( tried with array etc ...)

Is there a way that I can select part of the file listed in the dir and output it as below

for example if I input 0-2, it output as

00000\.MTS 00001.MTS 00002.MTS

same , if I input 3-5,

00003\.MTS 00004.MTS 00005.MTS

EXAMPLE FOLDER LIST

2022-03-24  00:14    \<DIR\>          .
2022-03-24  00:14    \<DIR\>          ..
2022-03-23  15:47         5,025,792 00000.MTS
2022-03-23  15:47         4,958,208 00001.MTS
2022-03-23  15:47         3,938,304 00002.MTS
2022-03-23  15:47         9,185,280 00003.MTS
2022-03-23  15:48         9,179,136 00004.MTS
2022-03-23  15:48         3,028,992 00005.MTS

The reason I try to do this it is because I would like to join the MTS files without typing in one by one in the command. The original command is like

copy /b 00000.MTS 00001.MTS 00002.MTS 00003.MTS 00004.MTS 00005.MTS "C:\\Users\\Desktop\\1.MTS"

Hope I can use the batch command
1st : 0-2

copy /b 00000.MTS 00001.MTS 00002.MTS "C:\\Users\\Desktop\\1.MTS"

2nd : 3-5

copy /b 00003.MTS 00004.MTS 00005.MTS "C:\\Users\\Desktop\\2.MTS"

Is it possible to complete this in bat ?

I did try with the for loop to gen the file list,

setlocal enabledelayedexpansion
set /P "mts1=MTS SET 1 : "
for %%n in (%mts1%) do (
echo !FILE_LIST\[%%n\]! 
)

but seem it only show all and also every file uses a new line, cannot be use in copy /b

CodePudding user response:

@ECHO Off
SETLOCAL ENABLEDELAYEDEXPANSION
rem The following settings for the source directory and destination directory are names
rem that I use for testing and deliberately include names which include spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.

SET "sourcedir=u:\your files\t w o"
SET "destdir=%sourcedir%"

:: Do we have 2 arguments?
IF "%~2" equ "" ECHO need 2 arguments&GOTO :eof

:: calculate the destination filename
SET /a destfile=0
:destloop
SET /a destfile =1
IF EXIST "           
  • Related