我必须重新编写在Linux中编写的代码,该代码用于检查文件夹中的新.txt文档,然后将它们转换为.pdf并通过电子邮件发送将该文档置于新.pdf中的用户。我对这种编码语言不是很熟悉,因此不知道更改代码所需的关键字,以便用python重写。改变了一些词语来保护身份。对格式化,第一篇文章抱歉。 这是原来的代码:将.txt重新写入Linux服务器的.pdf代码以在Windows Enterprise 2008服务器上工作
#This script checks the shares drive for "letters": txt files containing the contents of a letter to a customer.
#If it finds a letter, it uses a python script to convert that letter to a pdf, and then overlay that pdf on the
oldDir=`pwd`
sPath="/harris/SCRIPTS/regular_reports/txt2pdf"
iPath="/pdrive/letter2pdf/input"
oPath="/sdrive/letter2pdf/output"
processingPath="/harris/SCRIPTS/regular_reports/txt2pdf/processing"
cd "$iPath"
echo "Checking for $iPath/*.txt"
function run {
#Change to the input directory so I can use relative paths
cd "$iPath"
if ls -1 *.txt; then
#Get a list of all *.txt files in the input directory
list=`ls -1 *.txt`
#Loop through all files, processing one at a time
for file in $list; do
cd "$iPath"
#Move the input file to a temporary location for processing
mv ${file} "${processingPath}/"
cd "$processingPath"
echo ${file}
#The new file will be named the same, just with a .pdf extension
newfile=`echo "$file" | sed 's\.txt\.pdf\'`
#The email address to use is the file name (without extension), followed by @example.ca, so remove the extension.
email=`echo "$file" | sed 's|.txt||'`
echo "the new file is $newfile"
#Convert the text file to a PDF
python $sPath/txt2pdf.py $file
#Overlay the text on the letterhead
python $sPath/overlay.py "${file}.pdf" "${newfile}"
echo "[email protected]"
#The name of the file to email:
emailFile=`date '+%Y%m%d%H%M%S'`"Example.pdf"
outputFile="$oPath/`date '+%Y%m%d%H%M%S'`${newfile}"
cp "${newfile}" "$emailFile"
#If it's a new month, a folder will be created to hold the month's outputs
mkdir "$oPath/`date '+%B_%Y'`"
#Copy the file to the output (archival) directory
cp "${newfile}" "$oPath/`date '+%B_%Y'`/`date '+%Y%m%d%H%M%S'`${newfile}"
#Remove the file
rm "${newfile}"
mv "${newfile}" "$oPath/`date '+%Y%m%d%H%M%S'`${newfile}"
#Send the email
echo "Letter is attached." | mutt -e "my_hdr From:Letter2PDF<[email protected]>" -a "$emailFile" -s "Letter" "${email}@veridian.on.ca"
mv "${newfile}" "$oPath/`date '+%Y%m%d%H%M%S'`${newfile}"
#Remove the files we no longer need
rm "$file" "${file}.pdf"
done
else
echo "no valid files"
fi
cd "$oldDir"
}
run
rm $processingPath/*.pdf
堆栈溢出并不是真的让人们为你做你的工作的地方。这是一个要求特定编程问题的地方。那么告诉我们当你在Windows服务器上运行这个文件时会发生什么?什么是你得到的错误信息?询问如何解决您遇到的特定问题,并获得有用答案。 – aychedee
我不知道它写的代码,这就是为什么我发了帖子,看起来像我会从头开始。抱歉。 – jhan11
没关系!问一个关于堆栈溢出的问题有一些技巧。祝你的项目好运。 – aychedee