PowerShell obtains all files and folders in a directory, and replaces the obtained file path string
Foreword:
In order to compare the Java compiled file under the Windows system with the file on the Linux server, the acquisition and path processing of the file path are carried out.
Comparisons where there are only file paths and no actual files.
The code is as follows:
## grep ############################################ #Retrieve the path of the folder $findPath = "C:\wang\PowerShell\test\grep_cd_file\source" # output file path $grepKekka = "C:\wang\PowerShell\test\grep_cd_file\grepKekka.csv" $grepKekka1 = "C:\wang\PowerShell\test\grep_cd_file\grepKekka1.csv" $grepKekka2 = "C:\wang\PowerShell\test\grep_cd_file\grepKekka2.csv" # clear the output file Clear-Content $grep Kekka -Force Clear-Content $grepKekka1 -Force Clear-Content $grepKekka2 -Force # replace (\ : escape special characters) $String1 = 'C:\wang\PowerShell\test\grep_cd_file\source' $String2 = '/wang/PowerShell/test/grep_cd_file/source/' # get the files exclude folders $fileList = Get-ChildItem $findPath -Recurse * | where{<!-- -->!$_.PSIsContainer} foreach($file in $fileList) {<!-- --> #print the file name $file.name | Out-File -Width 5000 -FilePath $grepKekka1 -Append # print the file fullname $file.fullname | Out-File -Width 5000 -FilePath $grepKekka2 -Append } <# replace multiline comment #> (Get-Content $grepKekka2) -replace $String1, $String2 -replace '', '/' | Set-Content $grepKekka
Output file (grepKekka.csv):
/wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/day02_eesy_01mybatisCRUD.iml /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/pom.xml /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/.idea/.gitignore /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/.idea/compiler.xml /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/.idea/jarRepositories.xml /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/.idea/misc.xml /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/.idea/workspace.xml /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/src/main/java/com/itheima/dao/IUserDao.java /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/src/main/java/com/iheima/domain/QueryVo.java /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/src/main/java/com/iheima/domain/User.java /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/src/main/resources/jdbcConfig.properties /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/src/main/resources/log4j.properties /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/src/main/resources/SqlMapConfig.xml /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/src/main/resources/com/itheima/dao/IUserDao.xml /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/src/test/java/com/iheima/test/MybatisTest.java /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/target/classes/jdbcConfig.properties /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/target/classes/log4j.properties /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/target/classes/SqlMapConfig.xml /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/target/classes/com/itheima/dao/IUserDao.class /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/target/classes/com/itheima/dao/IUserDao.xml /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/target/classes/com/iheima/domain/QueryVo.class /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/target/classes/com/itheima/domain/User.class /wang/PowerShell/test/grep_cd_file/source/day02_eesy_01mybatisCRUD/target/test-classes/com/itheima/test/MybatisTest.class
Output file (grepKekka1.csv):
day02_eesy_01mybatisCRUD.iml pom.xml .gitignore compiler.xml jarRepositories.xml misc.xml workspace.xml IUserDao.java QueryVo.java User.java jdbcConfig.properties log4j.properties SqlMapConfig.xml IUserDao.xml MybatisTest.java jdbcConfig.properties log4j.properties SqlMapConfig.xml IUserDao.class IUserDao.xml QueryVo.class User.class MybatisTest.class
Output file (grepKekka2.csv):
C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\day02_eesy_01mybatisCRUD.iml C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\pom.xml C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\.idea\.gitignore C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\.idea\compiler.xml C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\.idea\jarRepositories.xml C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\.idea\misc.xml C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\.idea\workspace.xml C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\src\main\java\com\iheima\dao\IUserDao.java C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\src\main\java\com\iheima\domain\QueryVo.java C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\src\main\java\com\iheima\domain\User.java C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\src\main\resources\jdbcConfig.properties C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\src\main\resources\log4j.properties C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\src\main\resources\SqlMapConfig.xml C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\src\main\resources\com\itheima\dao\IUserDao.xml C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\src\test\java\com\iheima\test\MybatisTest.java C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\target\classes\jdbcConfig.properties C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\target\classes\log4j.properties C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\target\classes\SqlMapConfig.xml C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\target\classes\com\itheima\dao\IUserDao.class C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\target\classes\com\itheima\dao\IUserDao.xml C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\target\classes\com\iheima\domain\QueryVo.class C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\target\classes\com\iheima\domain\User.class C:\wang\PowerShell\test\grep_cd_file\source\day02_eesy_01mybatisCRUD\target\test-classes\com\itheima\test\MybatisTest.class
Conclusion:
In order to compare the Java compiled file under the Windows system with the file on the Linux server, the acquisition and path processing of the file path are carried out.
Comparisons where there are only file paths and no actual files.