我正在尝试将文件夹中的bmp文件转换为jpg,然后删除旧文件.代码工作正常,但它无法删除bmp.
DirectoryInfo di = new DirectoryInfo(args[0]);
FileInfo[] files = di.GetFiles("*.bmp");
foreach (FileInfo file in files)
{
string newFile = file.FullName.Replace("bmp", "jpg");
Bitmap bm = (Bitmap)Image.FromFile(file.FullName);
bm.Save(newFile, ImageFormat.Jpeg);
}
for (int i = 0; i < files.Length; i++)
files[i].Delete();
Run Code Online (Sandbox Code Playgroud)
这些文件没有被错误指示的其他程序/进程使用,所以我假设问题在这里.但对我来说,代码看起来很好,因为我按顺序执行所有操作.这也是程序的全部内容,因此错误不会由其他地方的代码引起.
例如,假设我有这个:
001, "john doe", "male", 37, "programmer", "likes dogs, women, and is lazy"
问题是该行只应该有6个字段.但是,如果我将它与split分开,我会得到更多,因为逗号被不正确地用于分隔字段.
现在我正在拆分所有东西,然后当我到达第5个索引时,我连接所有的字符串.但我想知道是否存在分裂(",",6)或沿着这些方向的东西.
def fraction?(number)
number - number.truncate
end
def percentile(param_array, percentage)
another_array = param_array.to_a.sort
r = percentage.to_f * (param_array.size.to_f - 1) + 1
if r <= 1 then return another_array[0]
elsif r >= another_array.size then return another_array[another_array.size - 1]
end
ir = r.truncate
another_array[ir] + fraction?((another_array[ir].to_f - another_array[ir - 1].to_f).abs)
end
Run Code Online (Sandbox Code Playgroud)
用法示例:
test_array = [95.1772, 95.1567, 95.1937, 95.1959, 95.1442, 95.061, 95.1591, 95.1195,
95.1065, 95.0925, 95.199, 95.1682]
test_values = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, …Run Code Online (Sandbox Code Playgroud) 这是我正在尝试做的事情:
val1 = [26, 27, 24, 25, 29, 28]
val2 = [17, 20, 22, 21]
val3 = [36, 33, 31, 29]
val4 = [20, 18, 17, 22, 21, 23]
vals = {val1, val2, val3, val4}
sum = 0
count = 0
vals.each do |val|
for i in 0..val.size-1 do
#sum += val[i]
p val[i]
++count
end
end
puts sum
puts count
Run Code Online (Sandbox Code Playgroud)
最初我想得到总和和数,但这不起作用,所以我尝试打印.我可以看到它val[i]并没有像我预期的那样工作.我试过这样做:
vals.each do |val|
aux = val.to_a
for i in 0..aux.size-1 do
p aux[i]
++count
end
end …Run Code Online (Sandbox Code Playgroud) 例如:
for(int i = 0; i < 100; i += 2)
我可以使用while循环或检查i%2 == 0,但我想知道是否没有办法用for循环来做.我也可以使用for(int i = 0; i < 50; i++)和乘以2,但这似乎也不正确.我只是想知道是否有一种简单,直接的方法来做到这一点.