batch file - creating folders based on Filename without overwriting -
working on script whereby staff scans in students exams certificates via photocopier , places copy location
the script below following
1) scans c:\users\location filename.pdf (the staff member manually enter student number @ photocopier , save file name that)
2) script creates folder based on filename here create folder called /filename
3) moves pdf folder
it works fine trying modify not overwrite
so if example staff member makes typo of student1 , student1 exists dont want override it
any suggestions
script below can test it
code: @echo off pushd c:\users\location %%f in (*.pdf) ( 2>nul md "%%~nf" >nul move /y "%%~nf*.*" "%%~nf" ) popd
you cannot overwrite folder md suppose talking move operation:
@echo off pushd c:\users\location %%f in (*.pdf) ( 2>nul md "%%~nf" echo n|move /-y "%%~nf*.*" "%%~nf" >nul 2>nul ) popd
or (might depend on local settings , expected input move /-y
)
@echo off pushd c:\users\location %%f in (*.pdf) ( 2>nul md "%%~nf" echo n|move /-y "%%~nf*.*" "%%~nf" 2>&1 |find /i "0 files(s)" >nul 2>nul || ( 2>nul md "%%~nf_2" move "%%~nf_2*.*" "%%~nf_2" >nul 2>nul ) ) popd
Comments
Post a Comment