I am trying to use a list of full file paths (mostly unique) (ex. "C:\Folder1\file_1.xls") to copy to full folder paths, (ex. "C:\DifferentFolder).
Both the full file path and full folder path differ by line. I have completed this using COPY mostly successfully, by placing all paths in quotes.
COPY "E:\California\CA_restaurants.pdf" "E:\Placestoeat\"
COPY "E:\California\CA_hotels.pdf" "E:\Placestostay\"
COPY "E:\Arizona\AZ_hotels.pdf" "E:\Placestostay\"
The issue with continuing to use this, is that I've found that I only have about a 95% success rate when I look at # of files before and after the .bat file is finished. I'm not sure what the issue is, but I'm considering switching to Robocopy or xcopy as I've heard those can give feedback about success AND an option to rename duplicate files??
Thing is, I can't seem to get either xcopy or robocopy to work based on full file names and full folder names, that both change each line.
Can someone explain what I'm doing wrong or give an example script for me to try? I'm not a techie, just trying to find a way to make my mundane historic data project more efficient.
If you open cmd.exe and type xcopy /?
you will see all of the valid switches, I am unsure what xcopy commands you have tried, but this should work without a doubt:
xcopy /Y "E:\folder paths\file.pdf" "E:\Placetostay"
I am however wondering why you would need to add each line to a file which you want to copy? That is alot of manual work, so much so that it might have been easier to just copy it manually. So why not automate it?
Here is a few ideas. This script will do a recursive search on your E:\
drive, if any file matches the name hotel
it will copy it to the relevant destination, unless the file that is searched is in the destination, simply because we do not want to copy a file to its own path again, Obviously the second option will do this for restaurants
as well:
Hotels:
@echo off
for /f %%i in ('dir /s /b /a-d *.pdf ^| findstr /i hotel') do (
if not "%%~dpi"=="E:\Placestostay\" xcopy "%%~fi" "E:\Placestostay"
)
Restaurants:
@echo off
for /f %%i in ('dir /s /b /a-d *.pdf ^| findstr /i restaurant') do (
if not "%%~dpi"=="E:\Placestostay\" xcopy /Y "%%~fi" "E:\Placestoeat"
)
Obviously the above can be combined as well.
Then, we can do the same, but let you chose what to search for by prompting the user for search criteria:
@echo off
set /p "search=Select search type (hotel, restaurant etc.): "
set /p "destination=Enter the destination to copy to (E:\placestoeat\ etc.): "
for /f %%i in ('dir /s /b /a-d *.pdf ^| findstr /i %search%') do (
if not "%%~dpi"=="%destination%" xcopy /Y "%%~fi" "%destination%"
)
Or similarly, pre-define the destination folder, based on the search:
@echo off
set /p "search=Select search type (hotel, restaurant etc.): "
if /i "%search%"=="hotel" set "destination=E:\placestostay\"
if /i "%search%"=="restaurant" set "destination=E:\placestoeat\"
for /f %%i in ('dir /s /b /a-d *.pdf ^| findstr /i %search%') do (
if not "%%~dpi"=="%destination%" xcopy /Y "%%~fi" "%destination%"
)