creating directory with user input

January 29, 2010 at 06:17:44
Specs: Windows XP
Hi
I want to copy pictures from a camera to a directory. I want my batch file
1. to prompt me for the "directory name" to be created.
2. rename pictures from xxxxx.jpg to 001.jpg 002.jpg and so on
3. copy all files into that directory.

Here is the code from Secret_Doom
@echo off
set dirname=
:input
set /P dirname=Type directory name: %=%
if "%dirname%"=="" goto input
mkdir "%dirname%"
cd "%dirname%"

For step 1 it is working perfect. I need help with step 2 and 3

Thanks very much for your help in advance


See More: creating directory with user input

Report •


#1
January 29, 2010 at 19:00:25
@echo off > newfile & setLocal enableDELAYedeXpansion

set N=

for /f "tokens=*" %%a in ('dir/b/a-d x:\*.jpg') do (
set /a N+=1
if !N! lss 1000 set S=0!N!
if !N! lss 100 set S=00!N!
echo.copy "%%a" !S!.jpg
)


=====================================
Helping others achieve escape felicity

M2


Report •

#2
January 29, 2010 at 21:45:45
If you want to do all of those task use the following code,
which may help you out:
Let's just keep it simple, we could use FOR, along with some
assistance from debug to parse a log file with all the file
names and remove some lines from that file.

Code: by Paradox (XD-51)
@echo off
:start
cls
REM NO Quotation marks PLEASE
echo Enter Source Directory
set /p srcname=Dir:
echo Enter Destination Directory
REM Only enter the name of the directory not fullpath
set /p destname=Dir:
set FULLpath="C:\Documents and
Settings\%username%\Desktop\%destname%"
mkdir %FULLpath%
set i=0
REM Rename files in src dir
:ren_loop
if /i not exist "%srcname%\*.jpg" goto continue
ren "%srcname%\*.jpg" "0%i%.jpg"
set /a i=i + 1
goto ren_loop
REM Display %srcname% with dir, to make sure renaming
was done!
dir "%srcname%"
:continue
REM Done renaming all files in src directory
REM Now copying all files to
xcopy "%srcname%\*.jpg" %FULLpath% /Q
echo.
echo Done!
echo Please check "%srcname%" for copied files.
pause>nul
goto start
REM EOL

Use this code and see if it works. if not, send me your
feedback, and I will try to make it legit.
XD-51


Report •

#3
January 30, 2010 at 01:40:49
Thanks very much for reply. But this is not working as I would like it to be.
It must not prompt me for source directory. It is G:\100ND200\.
It must prompt me for the destination directory (Working fine in above script)
Files must be renamed in the destination directory (Not working in above script)


Here is the code I'm using
=======
@echo off
set dirname=
:input
set /P dirname=Type directory name:: %=%
if "%dirname%"=="" goto input
mkdir "%dirname%"
copy G:\100ND200\website\*.* "%dirname%"\
cd "%dirname%"
set count=0
for %%i in (*.jpg) do (
set name=%%i
call :countadd
)
:countadd
set /a count=count+1
ren "%name%" ""%dirname%"_%count%.jpg"
GoTo :eof
=======
Every thing is working fine except an error message
"system can not find the file"
Thanks for your help


Report •

Related Solutions

#4
January 30, 2010 at 04:12:19
@echo off > newfile & setLocal enableDELAYedeXpansion

set N=
pushd G:\100ND200
set /p D=destination ?

for /f "tokens=*" %%a in ('dir/b *.jpg') do (
set /a N+=1
if !N! lss 100 set S=0!N!
if !N! lss 10 set S=00!N!
copy "%%a" !D!\!S!.jpg
)


=====================================
Helping others achieve escape felicity

M2


Report •

#5
January 30, 2010 at 04:32:09
Thanks for help, but it is giving me an error message "file not found"
see screen shot
And it is not making any directory. I have placed this script at c:\
After executing this script there is a file at c:
newfile of 0 KB

Report •

#6
January 30, 2010 at 05:30:58
OOPS I left out the MD. But I don't know why you're getting the error.

============================
@echo off > newfile & setLocal enableDELAYedeXpansion

set N=
pushd G:\100ND200
set /p D=destination ?
md !D!

CD
echo you should now be in G:\100ND200
pause

for /f "tokens=*" %%a in ('dir/b *.jpg') do (
set /a N+=1
if !N! lss 100 set S=0!N!
if !N! lss 10 set S=00!N!
copy "%%a" !D!\!S!.jpg
)


=====================================
Helping others achieve escape felicity

M2


Report •

#7
January 30, 2010 at 05:43:50
Many many Thanks for your help. It is working now.
Only one more thing, Directory, I want to make shell not at the same place as my pictures. It is assumed to be at another hard disk. Can you please make that change for me as well.

Report •

#8
January 30, 2010 at 05:58:38
When prompted for destination, give drive and directory. Like this:

x:\myfiles


=====================================
Helping others achieve escape felicity

M2


Report •

#9
January 30, 2010 at 06:38:11
Thanks

Report •

#10
March 29, 2010 at 08:17:52
M2 & co., You guys are good! Thanks.
Everything worked well but I was looking some additions.
1- idk if we can set env so user just have to type in directory name instead of whole path?
2- Once created, a move command to move bunch of files starting with 1, 2, 3, 4 etc in pdf format and move to this new directory with new names as '1=pki', '2=res', '3=chklist' etc


Thanks.


Report •

#11
March 30, 2010 at 00:57:39
Are you the OP with a different user name?

Is this PDF mover a new issue?


=====================================
Helping others achieve escape felicity

M2


Report •


Ask Question