Jump to content

Batch Files Script required for creating folders based on Filename


Recommended Posts

Posted

Hi Guys

 

Working on a script whereby Staff Scans in Students Exams Certificates via Photocopier and it then places a copy to a location

 

the script below does the following

 

1) Scans to C:\users\location as filename.pdf (The Staff member will manually enter STudent number at the photocopier and it will save the file name as that)

 

2) Script then creates folder based on filename so here it will create a folder called /filename

 

3) Moves the PDF into that folder

 

it all works fine

however i am trying to modify it so it does not overwrite

 

so if for example staff member makes a typo of student1 and student1 already exists we dont want to override it

 

any suggestions

 

script is as below you can test it

 

 

@echo off
pushd C:\Users\location
for %%F in (*.pdf) do (
 2>nul md "%%~nF"
 >nul move /y "%%~nF*.*" "%%~nF"

)
popd

Posted

Here is the solution incase anyone needs it

 

 

@echo off

pushd C:\Users\location

for %%F in (*.pdf) do (

2>nul md "%%~nF"

echo n|move /-y "%%~nF*.*" "%%~nF" >nul 2>nul || (

2>nul md "%%~nF_2"

move "%%~nF_2*.*" "%%~nF_2" >nul 2>nul

)

 

)

popd

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...