MOVE--Examples
Suppose C:\LETTERS is a directory. To move the files ED.TXT and SIGRID.TXT
from the current directory to the LETTERS directory on drive C, type the
following at the command prompt:
move ed.txt,sigrid.txt c:\letters
To move the BILL.TXT file from the current directory to the LETTERS
directory on drive C and rename it ANN.TXT, type the following at the
command prompt:
move bill.txt c:\letters\ann.txt
To rename the THISYEAR directory on drive C to LASTYEAR, type the following
at the command prompt:
move c:\thisyear c:\lastyear
MOVE--Batch Example
REM: DOS 6x filename limit: 8+3 characters.
@echo off
goto 0 (Create test items)
How to rename subdirectories in folder1:
----------------------------------------
(mm = month)
Current names are mm-dd-yy but instead I
want any subdirectories named mm-dd-20yy
Example: Rename: 01-01-00 => 01-01-2000
through 12-31-00 => 12-31-2000
----------------------------------------
:0 Create test items:
md folder1
md folder1\01-01-00
md folder1\12-31-00
cd folder1
set y=00
set m=01 02 03 04 05 06 07 08 09 10 11 12
set d=%m% 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
:1 solution (the following line should be 145 characters long, not 76 char:)
for %%m in (%m%) do %comspec%/c for %%d in (%d%) do if exist %%m-%%d-%y%\
nul if not exist %%m-%%d-20%y%\nul move %%m-%%d-%y% %%m-%%d-20%y%>nul
goto end
:2 solution
rem> q.tmp
for %%m in (%m%) do %comspec%/c for %%d in (%d%) do ECHO if exist %%m-%%d-
%y%\nul if not exist %%m-%%d-20%y%\nul move %%m-%%d-%y% %%m-%%d-20%y%>>q.tmp
find /v "ECHO if " < q.tmp | find " " > q.bat
for %%v in (call erase rename:q.tmp erase goto:end) do %%v q.bat
Notes:
The long line in the above solution is the same as in the first
solution, except: an ECHO prefix and a file redirection >>q.tmp
Content of q.bat, 12 * 31 = 372 lines:
---snip
if exist 12-31-00\nul if not exist 12-31-2000\nul move 12-31-00 12-31-2000
The first FIND avoiding the "DOS prompt" along with an extra output caused
by echoing on. The second FIND avoiding 372 blank lines:
find /v "ECHO if " < q.tmp | find " " > q.bat
which can be reduced
to
find "y%% " < q.tmp > q.bat
or
find "-%%y" < q.tmp > q.bat
but then %%%%%%%%y%%%%%%%% is required in the nested FOR loop at least once.
Example ---snip: ECHO move %%m-%%d-%%%%%%%%y%%%%%%%% %%m-%%d-20%y%
Output: move 12-31-%y% 12-31-2000
Extra notes:
Number of P (percent (%)) to append/prefix the variable y:
a append
o output
Pa = 8 Po +n
Pa = 8 *1 +0 (n=0, value don't exist in content: (set %y%=etc))
:end
for %%v in (m d y) do set %%v=
|