Основное решение:
def neighbors( list ):
i = 0
while i + 1 < len( list ):
yield ( list[ i ], list[ i + 1 ] )
i += 1
for ( x, y ) in neighbors( list ):
print( x, y )
If you want "bad" filenames to generate an error:
if (Path.GetFileName(fileName) != fileName)
{
throw new Exception("'fileName' is invalid!");
}
string combined = Path.Combine(dir, fileName);
Or, if you just want to silently correct "bad" filenames without throwing an exception:
string combined = Path.Combine(dir, Path.GetFileName(fileName));
Вы можете использовать:
Path.Combine(folder, Path.GetFileName(fileName))
или, чтобы пропустить \ (не проверено, возможно, Path.GetFileName обрабатывает это автоматически)
Path.Combine(folder, Path.GetFileName(fileName.Replace("/","\\")))