0
@ECHO Off
SETLOCAL ENABLEDELAYEDEXPANSION
SET "drives=d e f g h i j k l m n o p q r s t u v w x y z"
SET "sourcedir=normal"
REM locate drive that has directory "?:\normal\f"
FOR %%d IN (%drives%) DO IF EXIST "%%d:\%sourcedir%\f\." SET "sourcedir=%%d:\%sourcedir%"&SET "destdir=%%d:\video"&GOTO founddrive
ECHO Could not find "%sourcedir%\f" on any drive
GOTO :eof

:founddrive
SET /a destnum=1
FOR /f "delims=" %%a IN (
    'dir /b /a-d "%sourcedir%\f\*.TS"'
) DO (
    MD "%destdir%!destnum!" 2>NUL
    SET "filename=%%~na"
    SET "filename=!filename:~0,-1!R%%~xa"
    MOVE /y "%sourcedir%\F\%%a" "%destdir%!destnum!\video.MP4"
    MOVE /y "%sourcedir%\R\!filename!" "%destdir%!destnum!\video2.MP4"
    For /f "Tokens=1,2 Delims= " %%A in ('dir /T:C "%destdir%!destnum!\video.MP4" ^| Find /I "%destdir%!destnum!\video.MP4"') Do Echo " Starting Date,%%A,,,,,,,,,,,,,,,,,,,,,,,,,, ">>%destdir%!destnum!\info.csv
    For /f "Tokens=1,2 Delims= " %%A in ('dir /T:C "%destdir%!destnum!\video.MP4" ^| Find /I "%destdir%!destnum!\video.MP4"') Do Echo " Starting Time,%%B,,,,,,,,,,,,,,,,,,,,,,,,,, ">>%destdir%!destnum!\info.csv
    SET /a destnum+=1
)

thanks to @Magoo for helping with the core of this script. i found i need to do 1 more task and generate a CSV file with the date and time. where i am stuck is with

this creates info.csv but gives me 2 lines in the correct directory but the inf.csv file is not formatted as a proper CSV. everything but the variables are in 1 cell comma's included.

Do Echo " Starting Date,%%A,,,,,,,,,,,,,,,,,,,,,,,,,, ">>%destdir%!destnum!\info.csv

if i remove the quotes the whole script bombs out

Do Echo Starting Date,%%A,,,,,,,,,,,,,,,,,,,,,,,,,,>>%destdir%!destnum!\info.csv

thanks in advance.

1
  • try ... Do Echo Starting Date,"%%A",,,,,,,,,,,,,,,,,,,,,,,,,,>> ... Commented Jan 3, 2021 at 15:24

1 Answer 1

1

Hmm. It shouldn't.

dir /T:C "%destdir%!destnum!\video.MP4" output should not contain the string "%destdir%!destnum!\video.MP4" so no matches should be found, hence neither echo should occur. Now video.mp4 is far more likely to generate a hit.

So, to generate the .csv, try

 For /f "Tokens=1,2 Delims= " %%A in ('dir /T:C "%destdir%!destnum!\video.MP4" ^| Find /I "video.MP4"') Do (
  Echo "Starting Date","%%A",,,,,,,,,,,,,,,,,,,,,,,,,,
  Echo "Starting Time","%%B",,,,,,,,,,,,,,,,,,,,,,,,,,
  )>"%destdir%!destnum!\info.csv"

Note that there's no point in running dir twice. The syntax (...)>filename will create a new file filename containing the output-to-console from any commands between the parentheses. Use >> to append to any existing filename if desired.

Personally, I'd establish a variable which I'll arbitrarily and for no particular reason call commas containing a long string of potatoes and then replace the comma-sequence in the echoes with %commas:~-x% where x is the number of commas required. Saves going cross-eyed counting the little perishers, especially if there's a need to change the count.

Sign up to request clarification or add additional context in comments.

2 Comments

i added your suggested code and the batch file would blink then exit with no acctions. i removed the quotes from the last line )>"%destdir%!destnum!\info.csv" and BOOM it worked. the commas were from opening the CSV file with a text editor. there are a few more lines that need to be created that fill more cells but i removed them for clarity of my question. ill experiment with %commas:~-x% to see how that works. thank you, you are a gentleman and a scholar.
Removing those quotes should have absolutely no effect whatever on how the code works - they were there to cater for spaces in names. I'd suggest that perhaps the quotes had become "smart quotes" or WP-style inverted commas (I'd have referred to them as 66 and 99). Regardless, when you use the point-click-and-giggle method of executing a batch, the batch window will often close if a syntax-error is found. You should instead open a 'command prompt' and run your batch from there so that the window remains open and any error message will be displayed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.