What I am trying to do:
Read the contents of a text file where:
Column1 would create a directory with that value in column 1
Column2 would search another directory for the pdf name that is in the value of column 2 and copy that file to the newly created column1 directory.
Input.txt contents
DatabaseID,PDFNAME
1,sample12.pdf
2,sample18.pdf
3,sample1.pdf
4,sample35.pdf
5,sample46.pdf
What do you have so far? What part do you have questions about?
to be honest I was trying to do it through a batch job using DOS commands but any help or ideas would be great
If you share what you have so far, somone might know enough DOS to help. My kneejerk reaction with scripts like this is Python, but you should use whatever you’re most comfortable with (or whatever you’re most interested in learning).
@ECHO OFF
SETLOCAL
SET "sourcedir=c:\sourcedir"
SET "destdir=c:\destdir"
SET "textfiles=c:\bpd\*.txt"
:: For my testing
SET "textfiles=q20649661.txt"
FOR /f "usebackqtokens=1,2delims=, " %%a IN ("%textfiles%") do (
IF EXIST "%sourcedir%\%%a*.pdf" (
ECHO MD "%destdir%\%%b"
ECHO MOVE "%sourcedir%\%%a*.pdf" "%destdir%\%%b\"
)
)
GOTO :EOF
'fraid your specification is as clear as mud.
For my testing, I set up q20649661.txt with content
ABCDEFGH, STUVWXYZ
and established a file called c:\sourcedir\ABCDEFGH123.pdf
The result of the run was
MD "c:\destdir\STUVWXYZ"
MOVE "c:\sourcedir\ABCDEFGH*.pdf" "c:\destdir\STUVWXYZ\"
which I think is what you may want.
Note that appending 2>nul to the MD command will suppress ugly error message when the directory already exists.
I got it working…
@ECHO ON
SETLOCAL
SET “sourcedir=C:_trash\Tremco\PDF”
SET “destdir=C:_trash\Tremco\DEST”
::SET “textfiles=C:_trash\Tremco*.txt”
:: For my testing
SET “textfiles=C:_trash\Tremco\source.txt”
FOR /f “usebackqtokens=1,2delims=, " %%a IN (”%textfiles%") do (
IF EXIST “%sourcedir%%%a*.pdf” (
MD “%destdir%%%b”
MOVE “%sourcedir%%%a*.pdf” “%destdir%%%b”
)
)
GOTO :EOF
Created a source.txt that looks like
sample2, 2
sample1, 1
Created folder called DEST - this is where the folderds will be created
Created PDF folder and this is where all the PDF’s go
Congratulations on working through it!