Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
R
RemoveUnusedImg
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pengjunjing
RemoveUnusedImg
Commits
887e84ff
Commit
887e84ff
authored
Mar 02, 2023
by
pengjunjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:增加移动脚本
parent
dbf52e7b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
150 additions
and
0 deletions
+150
-0
MergeHelp.kts
...main/java/com/laihua/projecthelper/submerge/MergeHelp.kts
+100
-0
FileExt.kt
src/main/java/com/laihua/projecthelper/util/FileExt.kt
+50
-0
No files found.
src/main/java/com/laihua/projecthelper/submerge/MergeHelp.kts
0 → 100644
View file @
887e84ff
package
com.laihua.projecthelper.submerge
import
java.io.File
main
()
fun
main
()
{
println
(
"开始运行"
)
//要检查合并的目录
val
targetPath
=
"C:\\Android\\workspace\\laihua-hw"
val
targetFile
=
File
(
targetPath
)
//旧模块名字,未移动之前
val
mKtModelOldDirs
=
targetFile
.
listFiles
()
?.
filter
{
it
.
isDirectory
&&
it
.
name
.
startsWith
(
"m_kt"
,
true
)
}
//新模块的父目录位置
val
mKtModelNewParentDirs
=
targetFile
.
listFiles
()
?.
filter
{
it
.
isDirectory
&&
it
.
name
.
startsWith
(
"mod_"
,
true
)
}
//所有的不在子模块里面的文件
val
outModuleFiles
=
mutableListOf
<
File
>()
mKtModelOldDirs
?.
forEach
{
println
(
"旧模块文件夹列表:${it.name}"
)
val
allFilesIncludeSub
=
it
.
getAllFilesIncludeSub
()
outModuleFiles
.
addAll
(
allFilesIncludeSub
)
for
(
file
in
allFilesIncludeSub
)
{
println
(
"--> ${file.path}"
)
}
}
val
sumOf
=
mKtModelOldDirs
?.
sumOf
{
it
.
getAllFilesIncludeSub
().
size
}
println
(
"文件总数:$sumOf"
)
println
(
"----------------------------------------"
)
val
moveInfoList
=
mutableListOf
<
MoveInfo
>()
outModuleFiles
.
forEach
{
oldFile
->
var
tmpPath
=
oldFile
.
path
.
replace
(
targetPath
,
""
)
if
(
tmpPath
.
startsWith
(
File
.
separator
))
{
tmpPath
=
tmpPath
.
replaceFirst
(
File
.
separator
,
""
)
}
//所属模块名字
val
moduleName
=
tmpPath
.
substring
(
0
,
tmpPath
.
indexOf
(
File
.
separator
))
// println("新位置1 $tmpPath $moduleName")
mKtModelNewParentDirs
?.
forEach
{
newParentFile
:
File
->
newParentFile
.
listFiles
()
?.
find
{
it
.
name
==
moduleName
}
?.
let
{
newParentFileTarget
->
var
replace
=
oldFile
.
path
.
replace
(
targetPath
,
""
)
replace
=
replace
.
replaceFirst
(
"${File.separator}$moduleName"
,
""
)
replace
=
newParentFileTarget
.
path
+
replace
if
(
File
(
replace
).
exists
())
{
// println("新位置,存在相同文件 ${oldFile.path} -> $replace")
moveInfoList
.
add
(
MoveInfo
(
moduleName
,
oldFile
,
File
(
replace
)))
}
else
{
println
(
"新位置,需要新增的文件 ${oldFile.path} -> $replace"
)
}
}
}
}
println
(
"需要移动的总数:${moveInfoList.size}"
)
moveInfoList
.
forEach
{
}
}
class
MoveInfo
(
val
moduleName
:
String
,
old
:
File
,
new
:
File
)
{
}
/**
* 获取所有文件,包括子文件的子文件,(包含最深度的文件)
*/
fun
File
.
getAllFilesIncludeSub
():
List
<
File
>
{
if
(
this
.
isFile
)
{
throw
IllegalArgumentException
()
}
val
directory
=
this
val
files
=
mutableListOf
<
File
>()
if
(
directory
.
exists
()
&&
directory
.
isDirectory
)
{
directory
.
listFiles
()
?.
forEach
{
file
->
if
(
file
.
isFile
)
{
files
.
add
(
file
)
}
else
{
files
.
addAll
(
file
.
getAllFilesIncludeSub
())
}
}
}
return
files
}
src/main/java/com/laihua/projecthelper/util/FileExt.kt
0 → 100644
View file @
887e84ff
package
com.laihua.projecthelper.util
import
java.io.File
/**
* Author: pengjunjing
* Date: 2023/3/2
* Description:
*/
class
FileExt
{
}
/**
* 获取所有文件,包括子文件的子文件,(包含最深度的文件)
*/
fun
getAllFilesIncludeSub
(
path
:
String
):
List
<
File
>
{
val
directory
=
File
(
path
)
val
files
=
mutableListOf
<
File
>()
if
(
directory
.
exists
()
&&
directory
.
isDirectory
)
{
directory
.
listFiles
()
?.
forEach
{
file
->
if
(
file
.
isFile
)
{
files
.
add
(
file
)
}
else
{
files
.
addAll
(
getAllFilesIncludeSub
(
file
.
absolutePath
))
}
}
}
return
files
}
///**
// * 获取所有文件,包括子文件的子文件,(包含最深度的文件)
// */
//fun File.getAllFilesIncludeSub(): List<File> {
// if (this.isFile) {
// throw IllegalArgumentException()
// }
// val directory = this
// val files = mutableListOf<File>()
// if (directory.exists() && directory.isDirectory) {
// directory.listFiles()?.forEach { file ->
// if (file.isFile) {
// files.add(file)
// } else {
// files.addAll(file.getAllFilesIncludeSub())
// }
// }
// }
// return files
//}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment