I need help with a batch script.
I want one folder to sync with external usb device that has specific name (not drive letter; e.g. john's usb).
I found formula to sync folders:
robocopy "source folder" "destination folder" /e /purge
Source folder is not problem because it's specific folder on my drive but destination folder should be external usb with specific name (e.g. John's usb).
I can't do this using drive letters because sometimes I have more than 1 usb sticks connected in PC.
Hope someone can help.
Regards
find the correct drive letter:
for /f "usebackq tokens=2 delims=:=" %%a in (`wmic logicaldisk where VolumeName^="John's usb" get caption /value`) do set drive=%%a:
if "%drive%"=="" (
echo not inserted
) else (
echo inserted as %drive%
)
Related
I need to copy a number of files to multiple USB drives.
The USB drive letters are not static, so I need to create a script that will run the xcopy command on all USB drives with a label of "USB DISK".
I've found command lines that will do this for a single drive, but not multiple drives.
The command "for /f %%D in ('wmic volume get DriveLetter^, Label ^| find "My Label"') do set myDrive=%%D" works, but only on the last drive.
Is it possible to copy the files to all the drives at the same time, rather than one after another?
for /f %%D in (
'wmic volume get DriveLetter^, Label ^| find "My Label"'
) do start "Copying to %%D" xcopy "sourcespec" %%D:
should parallel xcopy your source files to each selected drive. xcopy options and specifications are in your court
I'm trying to create a batch script file to help an administrative assistant in my work group. Let's call him John.
John receives many CDs daily from clients containing architectural drawings as PDFs. Each CD is unique. John assigns it an Application Number, and creates a new folder on the network drive with the Application Number as the folder name. John then copies all the files on the CD to the newly created folder name. He repeats this process for every CD he receives.
I don't have any programming experience so I hope you can lend me a hand. Here's what I wrote below but it's not working. I get an "Insufficient memory" error. A new folder name based on the user input is correctly created on the network drive path but it's empty.
Thanks for your help! FYI, I'm running Windows 7 64-bit
#echo off
echo Welcome team member!
pause
set /p anumber=Type in the Application Number then press Enter key when done.
mkdir "S:\ARCH\Active Forms and Files\Submittal Floor Plans\%anumber%\"
:: e:\ is the CD drive path
set source=e:\
:: S:\ is a network drive
set destination="S:\ARCH\Active Forms and Files\Submittal Floor Plans\%anumber%\"
xcopy %source%\* %destination%\* /s /e /l /h /i >nul
pause
exit
You were setting the variable %source% to e:\ which was the read by the interpreter as E:\\* when used in %source%\*, leading to an invalid directory. The same was being done to the %destination% variable.
Updated Script:
#echo off
set "networkFolder=S:\ARCH\Active Forms and Files\Submittal Floor Plans"
set "CDDrive=e:"
echo Welcome team member!
:input
set "applicationNo="
set /p "applicationNo=Enter the Application Number and press ENTER: "
if not defined applicationNo goto :input
set "newLocation=%networkFolder%\%applicationNo%"
:actions
md "%newLocation%"
xcopy %CDDrive%\* "%newLocation%" /s /e /i /h>nul
echo Completed!
pause
I am trying to create a simple batch script to test the Data transfer between two Thumb Drives connected to a Test PC. This is how the test must proceed:
Detect if the USB Drives are connected to the PC.
If connected, detect the drive letters and assign them as Drive 1 and Drive 2
Test the Data Transfer by moving a file from the PC's Hard Drive to Drive 1. Move the same file from Drive 1 to Drive 2. Move the same file from Drive 2 back to the PC.
Repeat the same test by moving a file from the PC's Hard Drive to Drive 2. Move the same file from Drive 2 to Drive 1. Move the same file from Drive 1 back to the PC.
So far have managed to create the script (Script1) to detect the drive letters. I also have the script (Script2) to transfer the file as described in Points 3 and 4 (But here, the drive letters are fixed). However, I am not able to use the detected drive letters to transfer my file.
I am looking for a way to combine Script1 and Script2. Is there a way to do this? Is there a way to use the detected drive letters and execute the data transfer between the two?
It would be great if you could suggest an alternative solution as well.
Script1 to detect the drive:
#echo off
for /F "tokens=1*" %%a in ('fsutil fsinfo drives') do (
for %%c in (%%b) do (
for /F "tokens=3" %%d in ('fsutil fsinfo drivetype %%c') do (
if %%d equ Removable (
echo Drive %%c is Removable (USB^)
)
)
)
)
Script2 is a simple script to move a file (fixed name) from one drive to the other:
#echo off
Echo Moving File from PC to USBDrive1
move E:\Test1.txt N:\
Echo Moving File from USBDrive1 to USBDrive2
move N:\Test1.txt D:\
Echo Moving File from USBDrive2 to PC
move D:\Test1.txt E:\
I'm trying to make a Back Up.bat file using the RoboCopy command and am having some issues.
What I need is to back up a folder on to an external hard drive, and back up the same folder on to my laptop. My only issue is that the drive letter for my Hard Drive changes sometimes, I would just go to disk management and have a permanent drive letter, but I plan on having the folder backed up to multiple devices and don't want to have to repeat this again and again.
What I've tried so far is:
#echo off
robocopy "C:\Users\Zac\Desktop\Downloading" "%~d0\Backup\File Backups" /E /XF
robocopy "%~d0\Backup\File Backups" "C:\Users\Zac\Desktop\Downloading" /E /XF
I've also tried swapping the "%~d0" for a variety of drive letters, but got no where.
The easy way out is to make the drive letter permenent as shown in the Link.
you can look up the drive letter if you have the volume name:
set "drive=undefined"
for /f "tokens=2 delims=," %%i in ('wmic logicaldisk where (VolumeName ^= "ExternalDrive"^) get caption^,status /format:csv') do set drive=%%i
echo %drive%
where "ExternalDrive" is the volume name of your disk.
(Note: the property status is not used, it's just one of several ways to get rid of the ugly wmic line ending with the desired token caption)
I am trying to find a way to create a Windows batch script that will look at a target folder full of .pdf files and move (or copy) them to another directory with existing subfolders based on the filename.
The files and folders are names of actual people. I want to be able to get that person's pdf into their existing folder using a script.
Say I have 2 files in my folder; smithJohn015.pdf and thomasBill030.pdf.
I would like to be able to put smithJohn015.pdf into folder SmithJohn and thomasBill030.pdf into folder ThomasBill.
I don't want the script to create new folders or overwrite existing files if there's a duplicate filename.
I'm not necessarily looking for anyone to write a script for me, but if anyone can just get me started in the right direction it would be appreciated.
Try modifying this answer for your evil purposes.
#echo off
setlocal
pushd "c:\path\to\PDFs"
for /d %%I in (c:\Path\To\People\*) do (
for %%F in (*) do (
for /f %%A in ('echo %%~nF ^| find /i "%%~nI"') do (
set /p a="Moving %%F to %%I... "<NUL
move "%%F" "%%I" >NUL
echo Done.
)
)
)
popd
You'll need to add a check for if not exist pdffile before the move, but there's a starting direction for you anyway.
The following assumes the target subfolders' location contains only the subfolders where the PDFs may go and that every PDF that you want to move has a name formatted as the corresponding subfolder's name followed by exactly three characters (same as in your examples):
#ECHO OFF
FOR /D %%D IN ("D:\path\to\subfolders\*") DO (
MOVE "D:\path\to\PDFs\%%~nD???.pdf" "%%D"
)
Or as a one-liner to execute directly at the command prompt:
FOR /D %D IN ("D:\path\to\subfolders\*") DO (MOVE "D:\path\to\PDFs\%~nD???.pdf" "%D")
folderlist.txt contains all names of folders in which you want to copy respective PDFs.
xcopy is copy command. format xcopy "source" "destination" /parameters.
pause is just to keep command window on
for /F "tokens=*" %%A in (folderlist.txt) do (
xcopy "E:\path\to\source folder\<prefix>%%A<suffix>.pdf" "E:\path\to\destination folder\<prefix>%%A<suffix>\" /s)
pause
You can use wildcards in source & destination paths.