graysky Posted November 5, 2006 Share Posted November 5, 2006 Goal of batch file: 1) make a dir the users specifies and 2) copy files to that newly created dir.Problem is what I came up with doesn't work if the user specifies a name with spaces (non DOS 6.2 rules).cls@echo offecho set /p target=Please enter the directory name: mkdir %target%If the user enters a single word, it works just fine. If the user enters several words separated by a space, it doesn't work.Can someone help? The final line of the batch file will be something like:move f:\*.* %target% . Link to comment Share on other sites More sharing options...
bledd Posted November 5, 2006 Share Posted November 5, 2006 (edited) mkdir "%target"move f:\*.* "%target%"does that work?-edit, yes, yes it does Edited November 5, 2006 by bledd Link to comment Share on other sites More sharing options...
graysky Posted November 5, 2006 Author Share Posted November 5, 2006 (edited) Sure does, thanks man!edit - now is there a way I can start the windows xp copy or move command rather than using the DOS command? (I.e. launch whatever exe windows uses when a user does a drag-and-drop that will invoke the standard "Copying ..." dialogbox? Edited November 5, 2006 by graysky Link to comment Share on other sites More sharing options...
IcemanND Posted November 5, 2006 Share Posted November 5, 2006 I don't think you can from dos you can from a vbscript though.Const moveOrRenameTrue = 8Const yesToAll = 16Const displayProgress = 256Const noConfirmDirCreate = 512Set objShellApp = CreateObject("Shell.Application")set toFolder=objShellApp.NameSpace(Destination)toFolder.CopyHere Source, moveOrRenameTrue + yesToAll + displayProgress + noConfirmDirCreate Link to comment Share on other sites More sharing options...
Yzöwl Posted November 5, 2006 Share Posted November 5, 2006 As a side note (complaint) to your original 'batch code', you really need to use some sort of error trapping.For exampleyour user uses a blank nameyour user makes a mistakeyour user inputs illegal charactersyour user types a name of a folder which already existsThe 'batch language' is not the best choice to cover these sorts of things, however an attempt should be made to do so.<Edit>Here is an easy read example which covers the above scenarios reasonably well.@ECHO OFFSETLOCAL ENABLEEXTENSIONSSET BN="%TEMP%\_BADNAME.DAT"SET MN="%TEMP%\_MYNAME.DAT">%BN% ( ECHO.\ ECHO./ ECHO.* ECHO.^| ECHO.^< ECHO.^> ECHO.: ECHO.? ECHO., ECHO.^"):FOLDNAMEFOR %%? IN (NAME Z ANSR) DO (SET %%?=)CLS(SET /P NAME= PLEASE ENTER YOUR CHOSEN DIRECTORY NAME: )<NUL (SET /P Z=%NAME%)>%MN%IF DEFINED NAME (GOTO CHKIT)CLSECHO/ BLANK NAMES ARE NOT ACCEPTED!ECHO/SET /P "ANSR= DO YOU WISH TO CHOOSE A DIRECTORY NAME (Y/N)? "IF /I '%ANSR:~0,1% NEQ 'Y (GOTO EOF)GOTO FOLDNAME:CHKITECHO/%NAME%|FINDSTR/G:"%BN%" %MN%||GOTO RSURECLSECHO/ YOUR NAME CONTAINS ILLEGAL CHARACTERS!ECHO/ECHO/ PLEASE CHOOSE ANOTHER DIRECTORY NAME.PING -n 4 LOCALHOST>NULGOTO FOLDNAME:RSURECLSIF DEFINED ANSR (SET ANSR=)ECHO/ECHO/ THE DIRECTORY NAME YOU HAVE CHOSEN ISECHO/ECHO/ %NAME%ECHO/SET /P "ANSR= WOULD YOU LIKE TO CHANGE IT (Y/N)? "IF /I '%ANSR:~0,1% EQU 'Y (GOTO FOLDNAME):UNUSEDIF NOT EXIST %NAME% GOTO DONECLSECHO/ THE NAME YOU HAVE CHOSEN ALREADY EXISTS!ECHO/ PLEASE CHOOSE ANOTHER DIRECTORY NAME.PING -n 4 LOCALHOST>NULGOTO FOLDNAMECLS:DONEECHO/ECHO/ YOU'VE CHOSEN A NEW VALID DIRECTORY NAMEDECHO/ %NAME%PAUSE:EOFDEL %BN% %MN%You would replace or add to the data beneath the DONE label</Edit> Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now