0

I am looking for a small, free program I can use to move files from one folder to another. I've done a little research and think Batch files might be my best bet. Unfortunately, I've never used Batch files before and have absolute basic programming skills (took a computer science course on Java in college).

This is what I am looking for:

I have multiple folders within one specific folder (.....\Phase_2_Document_Prep) that have lots and lots of PDF files within, over 25,000.

I also have a master Excel Spreadsheet that contains the File Name of each PDF document and the Folder they are supposed to be in. As of now, the current files are all mixed up with different folders. I can create a pipe delimited text file that only has file name and folder.

I need a program that will import a txt file containing the file name and target folder, search through the current one specific folder and sub folders to find the file name (PDF) and move each file to the target folder.

============== UPDATE ======================= This is the code I'm working with but I keep getting ...\FILES was unexpected at this time error and nothing is copying.

Code:

set FILELIST=C:\Users\mcuomo\Documents\Test\Mudd_3_List.txt
set FILESPATH=C:\Users\mcuomo\Documents\Test\FILES
set DESTPATH=C:\Users\mcuomo\Documents\Test\TARGET

for /f %%X in (%FILELIST%) do call :COPY_FILES "%%X"
goto :eof

:COPY_FILES
for /f %FILESPATH% %%I in (%~1) do echo xcopy /w /v "%%I" "%DESTPATH%%%~pnxI"
PAUSE

thanks again

1
  • 4
    Why not start learning about batch files? We are not a free software writing service
    – Ed Heal
    Jan 31, 2014 at 18:31

3 Answers 3

1

The error is being generated by the for loop under :COPY_FILES.

Check the help for how to use the for command - for /?. The /F switch can be used in the following ways according to the help -

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]

Perhaps you want to change your second for loop to -

for /f %%I in (%~1) do echo xcopy /w /v "%FILESPATH%\%%I" "%DESTPATH%\%%~pnxI"

Since you haven't included it, I'm not sure if the backslash is needed between the path and the file name (%FILESPATH% and %%I). I might be able to make this more useful if you can provide an example of the content of Mudd_3_List.txt.

1

Your problem seems to be this line:

for /f %FILESPATH% %%I in (%~1) do echo xcopy /w /v "%%I" "%DESTPATH%%%~pnxI"

Syntax should be:

for /f %%i in (%~1) do ...

or

for /f "<options>"  %%i in (%~1) do ...

See for /? for documentation. By the way: you should use ("%~1") to be able to handle filenames with spaces.

1

The is non-destructive and will merely create Mudd_3_List.txt.bat.txt in the same folder as the filelist so you can examine it in notepad, and then rename it to .bat to execute if you are happy with it.

The actual filelist Mudd_3_List.txt needs to be saved from Excel in this comma-delimited format on each line

folder_path,Filename

Such as this: make sure that no folder names have a comma in them.

c:\new folder1\folder B\,Old pdf nameA.pdf
c:\new folder2\folder five\,Old pdf nameB.pdf

Change this folder below to suit you "c:\folder\Phase_2_Document_Prep"

Here's the script to create the file:

@echo off
set "FILELIST=C:\Users\mcuomo\Documents\Test\Mudd_3_List.txt"
for /f "tokens=1,* delims=," %%a in ('type "%FILELIST%" ') do (
    for /r "c:\folder\Phase_2_Document_Prep" %%f in ("%%~b") do (
       >>%FILELIST%.bat.txt" echo md "%%~a" 2^>nul & move "%%~f" "%%~a"
    )
)
1
  • This has been changed - hopefully it will help
    – foxidrive
    Feb 1, 2014 at 8:40

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.