[英]Slashes in file names when migrating PHP project to Windows server from Linux server
[英]Migrating a legacy PHP Project from Windows to Linux (inconsistent case disaster)
我有一個低質量的PHP項目(我沒有寫它:))和向linux文件系統遷移的問題,也就是說,與Windows區分大小寫相反。 include和image-name與我需要一種自動解決方案的真實文件名有些矛盾。
因此,我想到了一個腳本,該腳本以遞歸方式解析php,js,jpg和gif文件的項目目錄,並用項目php文件中的真實文件名替換所有錯誤大小寫文件名的情況。
該算法將是這樣的:
foreach(php,js,jpg,png,gif ..)作為$ found在目錄中:在目錄中找到所有php:用$ found替換ignoreCase($ found)
我試圖用perl和File :: Find來寫這個,但是我目前卡住了:/
您可以使用find
和gnu-sed gsed
在命令行中執行此gsed
。
#!/bin/sh
# Replace filenames found in code and create a backup of original
find . -type f \( -name "*.php" -or -name "*.jpg" \) -exec bash -c 'gsed -i.bak "s/\(\W\)`basename {}`\(\W\)/\1`basename {}`\2/Ig" /src/ *' \;
########################
# Explanation
# find
# . : Recursively from current directory,
# -type f : files only - not folders,
# f\(..\) : with extensions,
# -ecec : execute this command,
# base -c : and execute in bash after {} replacement
# sed
# -i : Replace text in the actual file,
# .bak : but backup file to *.bak,
# s/ : search for;
# \W : something beginning with a
# non word so we dont match test.img with
# otherTest.img, but will still match "test.img"
# `basename {}` : file name placeholder provided by find
# \W : does not end in a word so we dont match
# test.htm against test.html
# /`basename {}`/ : Replace string from the search with the
# string of the actual filename
# g : Global search, match more than just the first instance
# I : Case insensitive search
# /src/* : Full path to files sed will work on
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.