Copy CD contents with CD name
Moderator: DosItHelp
Copy CD contents with CD name
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.
Re: Copy CD contents with CD name
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
Steffen
Re: Copy CD contents with CD name
CDs are usually in the D: drive and they are generally the same nomenclature 'N4660078013' just changing the numbers per CD.
Re: Copy CD contents with CD name
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.
Saso
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.
Re: Copy CD contents with CD name
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.
-
- Expert
- Posts: 1163
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Copy CD contents with CD name
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"
Re: Copy CD contents with CD name
Maybe. Zuhan is the only one who could tell us. That's the reason why I asked.Wouldn't it be the volume label?
Steffen
Re: Copy CD contents with CD name
Did you try my solution? It works for me.
Saso
Saso
Re: Copy CD contents with CD name
Run that code and tell us if one of these two methods captured the name.
Steffen
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
Re: Copy CD contents with CD name
The first code captured what I needed.aGerman wrote: ↑05 Apr 2020 14:07Run that code and tell us if one of these two methods captured the name.SteffenCode: 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
Re: Copy CD contents with CD name
Alright. Give this a go:
Steffen
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
Re: Copy CD contents with CD name
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.aGerman wrote: ↑05 Apr 2020 17:11Alright. Give this a go:SteffenCode: 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