xref: /reactos/base/shell/cmd/ren.txt (revision 463784c5)
1Made by Vicmarcal 23/11/08
2
3THIS FILE HELPS TO EXPLAIN HOW REN IS NOW IMPLEMENTED.
4****************************************************************
5(Please change or add latest modifications)
6****************************************************************
7Before detailing the Rem code just 3 things:
8
91)Ren can be used in 3 different ways:
10
11WAY #1:Full Path Way:
12ren c:\ie\hello.txt c:\ie\hi.txt
13
14rename command will change the name of hello.txt->hi.txt. We have to be sure that both paths(c:\ie\ ) be the same.Since rename cant move files within Directories (MSDN).
15
16WAY #2:Semi Path Way:
17ren c:\ie\hello.txt hi.txt
18
19This is a special feature,since this does the same as Way #1 but without telling the Destiny path.So this feature must be implemented also.
20
21WAY #3: Just file
22ren hello.txt hi.txt
23
24So it changes the name of hello.txt in the current directory.
25
262)Also can be used Wildcards.So be careful ;)
27
283)Syntax errors:
29
30-Way #1 with different Subdirectories path: ren c:\ie\hello.txt c:\hi\hi.txt, this is not possible.Since ren doesnt move files,just rename them.
31-Way #2 semi path in destiny: ren hello.txt c:\ie\hi.txt. This feature isn't available.
32
33
34**************************************************
35Explaining code:
36
37
38srcPattern: here is stored Source Argument (C:\ie\hello.txt)
39srcPath: here  is  stored Source Path(C:\ie)
40srcFILE: here  is  stored FILE name(hello.txt)
41
42dstPattern: here is stored Destiny Argument (C:\ie\hi.txt)
43dstPath: here  is  stored Destiny Path(C:\i)
44dstFILE: here  is  stored FILE re-name(hi.txt)
45
461)We begin retrieving arguments from command line and fulfilling dstPattern and srcPattern
47
48
492)If srcPattern contains "\" then:
50        -we activate bPath, since srcPattern has a path inside of it.
51        -we split the srcPattern to srcFile and srcPath.
52    -Now we check the dstPattern �does it contain a Path?:
53        -If does: we divide it in dstPath and dstFile.AND ALSO CHECK THAT dstPath and srcPath it�s the same(see syntax error).If they aren the same we launch an error.
54        -If doesnt then we copy srcPath to dstPath(see #way2) and also saving dstPattern as dstFile.
553)If srcPattern doesnt contain "\" then:
56        -srcPattern is copied in srcFile(we dont need a previous split,because it�s just a name)
57    -Now we check the dstPattern �does it contains a Path?
58        -If does: we launch an error (see syntax error 2)
59        -If doesnt: we copy dstPattern to dstFile(we dont need a previous split because it�s just a name)
60
614)Now we are entering in the do...while:
62
63"p" will store a REAL name file(It uses f.cFileName)
64Real name file is the name that FindFile returns us.FindFile return NULL if it doesnt find the Source File that we want to  rename.And returns the name if finds it.
65
66Do while is used to manage Wildcards.So we can iterate Finding all the files with the Wildcards in it.
67But wildcards (? and *) has different behavior so we have to be carefull.
68
69"q" stores the srcFile(this can be a real name file but ALSO A NAME FULL OF WILDCARDS)(p always has a REAL NAME)(This is the most difficult point to understand the code)
70"r" is the Name File after applying the Mask (q)(it�s stored in dstLast).
71
72If we are just renaming one file,then we dont make the while loop.The do..while loop is made when some files are renamed: i.e ren *.lol *.rem
73
745)Now we have to check our Boolean.
75
76bPath==TRUE means that Source Argument was a Path so now we have to Join again the Path with the Name File:
77    -srcFINAL: srcPath+f.cFileName
78    -dstFINAL: dstPath+dstFile
79bPath==False then Source wasn a Path an we dont need to join anything.
80    -srcFINAL:f.cFileName
81    -dstFINAL:dstFile
82
83
84At last we just make a MoveFile(srcFinal, dstFinal)):
85
86Also there are a Bunch of Flags (the options)
87.It makes the code more difficult to understand.But they are just option flags that show or hides errors,that prevents system files to be renamed...and so.
88
89
90
91
92