Copy CD contents with CD name

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Zuhan
Posts: 10
Joined: 03 Apr 2020 14:33
Location: Yokosuka, Japan

Copy CD contents with CD name

#1 Post by Zuhan » 03 Apr 2020 14:43

I need a little help. I'm trying to make a batch file to make my job a little easier. I have to upload a large amount of CDs and these CDs need to be put into each of their own folders with their respective CD names/labels. Going one CD at a time and naming each folder as the CD can be a huge pain in the rear end, not to mention if the folder is not named correctly I can't upload it to the program that its needed in. Any help would be very much appreciated, thank you for your time.

aGerman
Expert
Posts: 3888
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Copy CD contents with CD name

#2 Post by aGerman » 04 Apr 2020 06:11

And from where should a batch code read the CD name? And if it would be able to do so, what should happen if it contains characters that are invalid in the file system?

Steffen

Zuhan
Posts: 10
Joined: 03 Apr 2020 14:33
Location: Yokosuka, Japan

Re: Copy CD contents with CD name

#3 Post by Zuhan » 04 Apr 2020 10:00

CDs are usually in the D: drive and they are generally the same nomenclature 'N4660078013' just changing the numbers per CD.

miskox
Posts: 352
Joined: 28 Jun 2010 03:46

Re: Copy CD contents with CD name

#4 Post by miskox » 04 Apr 2020 11:35

This could be a start. Replace three strings with your data (this could be automated but requires more time). If folder already exists .cmd exits. Change XCOPY qualifiers if required. ECHO BEL coudl be added at the end so you know when the operation completes.

Code: Select all

@echo off
:begin
REM Update strings below to your situation
set volume_string=Volume in drive&rem
set cd_drive=D:
set volume_string_long= Volume in drive D is &rem

echo Insert a CD and press any key to continue.
pause

dir %cd_drive%|find /i "%volume_string%">label.cd
set /p cd_label=<label.cd
set cd_label=%cd_label: Volume in drive D is =%

echo Copying files from the CD labeled %cd_label%...

if exist label.cd del label.cd
if exist "%cd_label%" echo This folder already exists.&&goto :EOF
md "%cd_label%">nul

REM Windows XP PRO, 32-bit (newer versions might have more options)
REM  /E           Copies directories and subdirectories, including empty ones.
REM  /V           Verifies each new file.
REM  /Q           Does not display file names while copying.
REM  /H           Copies hidden and system files also.

xcopy %cd_drive% "%cd_label%\" /E /V /Q /H 
set errlev=%errorlevel%
if "%errlev%"=="0" (
	echo Copying of %cd_label% completed successfuly.
) ELSE (
	echo Errors occured.
)
goto :BEGIN

REM XCOPY help:
XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                           [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
                           [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
                           [/EXCLUDE:file1[+file2][+file3]...]

  source       Specifies the file(s) to copy.
  destination  Specifies the location and/or name of new files.
  /A           Copies only files with the archive attribute set,
               doesn't change the attribute.
  /M           Copies only files with the archive attribute set,
               turns off the archive attribute.
  /D:m-d-y     Copies files changed on or after the specified date.
               If no date is given, copies only those files whose
               source time is newer than the destination time.
  /EXCLUDE:file1[+file2][+file3]...
               Specifies a list of files containing strings.  Each string
               should be in a separate line in the files.  When any of the
               strings match any part of the absolute path of the file to be
               copied, that file will be excluded from being copied.  For
               example, specifying a string like \obj\ or .obj will exclude
               all files underneath the directory obj or all files with the
               .obj extension respectively.
  /P           Prompts you before creating each destination file.
  /S           Copies directories and subdirectories except empty ones.
  /E           Copies directories and subdirectories, including empty ones.
               Same as /S /E. May be used to modify /T.
  /V           Verifies each new file.
  /W           Prompts you to press a key before copying.
  /C           Continues copying even if errors occur.
  /I           If destination does not exist and copying more than one file,
               assumes that destination must be a directory.
  /Q           Does not display file names while copying.
  /F           Displays full source and destination file names while copying.
  /L           Displays files that would be copied.
  /G           Allows the copying of encrypted files to destination that does
               not support encryption.
  /H           Copies hidden and system files also.
  /R           Overwrites read-only files.
  /T           Creates directory structure, but does not copy files. Does not
               include empty directories or subdirectories. /T /E includes
               empty directories and subdirectories.
  /U           Copies only files that already exist in destination.
  /K           Copies attributes. Normal Xcopy will reset read-only attributes.
  /N           Copies using the generated short names.
  /O           Copies file ownership and ACL information.
  /X           Copies file audit settings (implies /O).
  /Y           Suppresses prompting to confirm you want to overwrite an
               existing destination file.
  /-Y          Causes prompting to confirm you want to overwrite an
               existing destination file.
  /Z           Copies networked files in restartable mode.

Saso

aGerman
Expert
Posts: 3888
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Copy CD contents with CD name

#5 Post by aGerman » 04 Apr 2020 12:45

Zuhan wrote:
04 Apr 2020 10:00
CDs are usually in the D: drive and they are generally the same nomenclature 'N4660078013' just changing the numbers per CD.
That still doesn't answer the question of where the script can read the name.

Steffen

Zuhan
Posts: 10
Joined: 03 Apr 2020 14:33
Location: Yokosuka, Japan

Re: Copy CD contents with CD name

#6 Post by Zuhan » 04 Apr 2020 13:06

aGerman wrote:
04 Apr 2020 12:45
Zuhan wrote:
04 Apr 2020 10:00
CDs are usually in the D: drive and they are generally the same nomenclature 'N4660078013' just changing the numbers per CD.
That still doesn't answer the question of where the script can read the name.

Steffen
I'm not sure what you are asking. I generally have my batch files on my desktop and run them from there.

If this helps.

Batch file will be located "C:\Users\'My Name'\Desktop"
CD is in D: drive
CD needs to be copied to "C:\Users\'My Name'\Desktop\'Required Folder'" with the CD name. If possible any user currently logged in.
From there I can run the program to upload it to the system.

If this is possible it will make my job 100% easier.
Last edited by Zuhan on 04 Apr 2020 14:05, edited 2 times in total.

ShadowThief
Expert
Posts: 972
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Copy CD contents with CD name

#7 Post by ShadowThief » 04 Apr 2020 13:30

aGerman wrote:
04 Apr 2020 06:11
And from where should a batch code read the CD name? And if it would be able to do so, what should happen if it contains characters that are invalid in the file system?

Steffen
Wouldn't it be the volume label?

Code: Select all

for /f "tokens=1-5,*" %%A in ('vol D:^| find "Volume in drive"') do set "disc_name=%%F"

aGerman
Expert
Posts: 3888
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Copy CD contents with CD name

#8 Post by aGerman » 05 Apr 2020 06:17

Wouldn't it be the volume label?
Maybe. Zuhan is the only one who could tell us. That's the reason why I asked.

Steffen

Zuhan
Posts: 10
Joined: 03 Apr 2020 14:33
Location: Yokosuka, Japan

Re: Copy CD contents with CD name

#9 Post by Zuhan » 05 Apr 2020 10:31

aGerman wrote:
05 Apr 2020 06:17
Wouldn't it be the volume label?
Maybe. Zuhan is the only one who could tell us. That's the reason why I asked.

Steffen
What do you mean? The name I am talking about is the name of the CD you see when you look at the CD drive. D:N466780014

miskox
Posts: 352
Joined: 28 Jun 2010 03:46

Re: Copy CD contents with CD name

#10 Post by miskox » 05 Apr 2020 10:48

Did you try my solution? It works for me.

Saso

Zuhan
Posts: 10
Joined: 03 Apr 2020 14:33
Location: Yokosuka, Japan

Re: Copy CD contents with CD name

#11 Post by Zuhan » 05 Apr 2020 13:14

miskox wrote:
05 Apr 2020 10:48
Did you try my solution? It works for me.

Saso
What variables do I need to change in it?

aGerman
Expert
Posts: 3888
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Copy CD contents with CD name

#12 Post by aGerman » 05 Apr 2020 14:07

Run that code and tell us if one of these two methods captured the name.

Code: Select all

@echo off

setlocal
echo 1.
for /f "delims=" %%i in ('wmic volume WHERE "Caption='D:\\'" GET Label /value') do for /f "delims=" %%j in ("%%i") do set "%%j"
echo %Label%
endlocal

setlocal
echo 2.
for /f "delims=" %%i in ('findstr /bic:"Label=" "D:\autorun.inf"') do set "%%i"
echo %Label%
pause
Steffen

Zuhan
Posts: 10
Joined: 03 Apr 2020 14:33
Location: Yokosuka, Japan

Re: Copy CD contents with CD name

#13 Post by Zuhan » 05 Apr 2020 16:49

aGerman wrote:
05 Apr 2020 14:07
Run that code and tell us if one of these two methods captured the name.

Code: Select all

@echo off

setlocal
echo 1.
for /f "delims=" %%i in ('wmic volume WHERE "Caption='D:\\'" GET Label /value') do for /f "delims=" %%j in ("%%i") do set "%%j"
echo %Label%
endlocal

setlocal
echo 2.
for /f "delims=" %%i in ('findstr /bic:"Label=" "D:\autorun.inf"') do set "%%i"
echo %Label%
pause
Steffen
The first code captured what I needed.

aGerman
Expert
Posts: 3888
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Copy CD contents with CD name

#14 Post by aGerman » 05 Apr 2020 17:11

Alright. Give this a go:

Code: Select all

@echo off &setlocal
for /f "delims=" %%i in ('wmic volume WHERE "Caption='D:\\'" GET Label /value') do for /f "delims=" %%j in ("%%i") do set "%%j"
robocopy "D:" "%userprofile%\Desktop\%Label%" /e /r:0 /w:0
Steffen

Zuhan
Posts: 10
Joined: 03 Apr 2020 14:33
Location: Yokosuka, Japan

Re: Copy CD contents with CD name

#15 Post by Zuhan » 05 Apr 2020 17:35

aGerman wrote:
05 Apr 2020 17:11
Alright. Give this a go:

Code: Select all

@echo off &setlocal
for /f "delims=" %%i in ('wmic volume WHERE "Caption='D:\\'" GET Label /value') do for /f "delims=" %%j in ("%%i") do set "%%j"
robocopy "D:" "%userprofile%\Desktop\%Label%" /e /r:0 /w:0
Steffen
That did the trick. Thank you for the help and sorry for all the questions and run around. Still a little new to this Batch File thing.

Post Reply