- Remove the remaining __USE_W32API, deprecated for ages.
[reactos.git] / reactos / base / shell / cmd / ren.txt
1 Made by Vicmarcal 23/11/08
2
3 THIS FILE HELPS TO EXPLAIN HOW REN IS NOW IMPLEMENTED.
4 ****************************************************************
5 (Please change or add latest modifications)
6 ****************************************************************
7 Before detailing the Rem code just 3 things:
8
9 1)Ren can be used in 3 different ways:
10
11 WAY #1:Full Path Way:
12 ren c:\ie\hello.txt c:\ie\hi.txt
13
14 rename 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
16 WAY #2:Semi Path Way:
17 ren c:\ie\hello.txt hi.txt
18
19 This 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
21 WAY #3: Just file
22 ren hello.txt hi.txt
23
24 So it changes the name of hello.txt in the current directory.
25
26 2)Also can be used Wildcards.So be careful ;)
27
28 3)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 isnt available.
32
33
34 **************************************************
35 Explaining code:
36
37
38 srcPattern: here is stored Source Argument (C:\ie\hello.txt)
39 srcPath: here is stored Source Path(C:\ie)
40 srcFILE: here is stored FILE name(hello.txt)
41
42 dstPattern: here is stored Destiny Argument (C:\ie\hi.txt)
43 dstPath: here is stored Destiny Path(C:\i)
44 dstFILE: here is stored FILE re-name(hi.txt)
45
46 1)We begin retrieving arguments from command line and fulffilling dstPattern and srcPattern
47
48
49 2)If srcPattern contains "\" then:
50 -we activate bPath, since srcPattern has a path inside of it.
51 -we explit 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.
55 3)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
61 4)Now we are entering in the do...while:
62
63 "p" will store a REAL name file(It uses f.cFileName)
64 Real 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
66 Do while is used to manage Wildcards.So we can iterate Finding all the files with the Wildcards in it.
67 But 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 aplying the Mask (q)(it´s stored in dstLast).
71
72 If 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
74 5)Now we have to check our Boolean.
75
76 bPath==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
79 bPath==False then Souce wasn a Path an we dont need to join anything.
80 -srcFINAL:f.cFileName
81 -dstFINAL:dstFile
82
83
84 At last we just make a MoveFile(srcFinal, dstFinal)):
85
86 Also 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