使用par2j64.exe创建奇偶校验存档工具,我用Ruby编写了一个脚本,为单个.rar文件创建奇偶校验存档,但也希望能够将其用于多部分.rar文件。
这适用于单个.rar文件:
# Set parameters for par2j64
parity_tool = "par2j64.exe"
redundancy_percent = "15"
par2_files = "8"
working_directory = "G:/Working"
# Find all RAR files in the specified working directory
rar_files = Dir.glob(File.join(working_directory, "*.rar"))
if rar_files.empty?
puts "No RAR files found in the specified working directory."
else
# Iterate over each RAR file
rar_files.each do |rar_file_path|
# Extract the filename from the file path
rar_file_name = File.basename(rar_file_path)
# Create parity archives for the RAR file
puts "Creating parity archives for #{rar_file_name}..."
Dir.chdir(working_directory) do
system("#{parity_tool} c /rr#{redundancy_percent} /rf#{par2_files} /rd1 \"#{rar_file_name}.par2\" \"#{rar_file_path}\"")
end
puts "Parity archives created for #{rar_file_name}."
puts
end
end
字符串
这个DOS脚本代码可以工作,但我不知道如何将它转换为Ruby脚本:
rem Search the first file of each splitted RAR archive
for %%F in ("*.part1.rar" "*.part01.rar" "*.part001.rar") do (
call :SUB_CREATE "%%~nF"
)
echo Parity archive creation complete.
pause
rem Exit script before sub routine
exit
:SUB_CREATE
rem Sub-routine to create PAR files for multiple input files
echo Creating parity archives for multiple %~n1...
%PARITY_TOOL% c /rr%REDUNDANCY_PERCENT% /rf%PAR2_FILES% /rd1 "%~n1.par2" "%~n1.part*.rar"
echo Parity archives created for multiple %~n1.
echo
rem exit subroutine
exit /B
型
我在Ruby中尝试过这样的事情,但没有成功:
# Set parameters
parity_tool = "par2j64.exe"
redundancy_percent = "15"
par2_files = "8"
working_directory = "G:/Working"
# Search the first file of each splitted RAR archive
Dir.glob("*.part1.rar") do |file|
create_parity(file)
end
Dir.glob("*.part01.rar") do |file|
create_parity(file)
end
Dir.glob("*.part001.rar") do |file|
create_parity(file)
end
puts "Parity archive creation complete."
puts "Press Enter to continue."
gets
# Method to create parity archives for multiple input files
def create_parity(file)
puts "Creating parity archives for multiple #{File.basename(file, ".*")}..."
system("#{parity_tool} c /rr#{redundancy_percent} /rf#{par2_files} /rd1 #{File.basename(file, ".*")}.par2 #{File.basename(file, ".*")}.part*.rar")
puts "Parity archives created for multiple #{File.basename(file, ".*")}."
puts
end
型
1条答案
按热度按时间83qze16e1#
好吧,我自己想出来的。我以前也试过这样的方法,但不明白为什么它不起作用。问题是多部分.rar文件中的“.part”作为基本文件名的一部分被包含在内,因此par2j64.exe找不到输入文件。以下Ruby脚本用于为多部分.rar文件创建奇偶校验存档,它假设par2j64.exe的路径已添加到Windows环境变量中,否则需要调用它,包括实际路径:
字符串