Delete empty lines snippet not working

allsystems

Client
Регистрация
08.07.2013
Сообщения
81
Благодарностей
1
Баллы
8
Hi,

So I have this snippet from a fellow member on this forum. Snippet is this:

// Delete blank lines from file
string path = project.Variables[@"{-Project.Directory-}Accounts.txt"].Value; // Gets file path from your project variable with name "filePath"
var lines = System.IO.File.ReadAllLines(path).Where(arg => !string.IsNullOrWhiteSpace(arg));
System.IO.File.WriteAllLines(path, lines);
return 0;

I have edited the snippet slightly and added the "@" before project directory path. It wont work without this. The issue is that Zenno picks up the file path but says no such variable so the .txt file Accounts.txt cannot be found. Accounts.txt exists so I am not sure what I am doing wrong. I am trying to delete all empty lines in the .txt file. Help is appreciated.

Thanks
 

bigcajones

Client
Регистрация
09.02.2011
Сообщения
1 216
Благодарностей
683
Баллы
113
Your code is wrong. {-Project.Directory-}Accounts.txt cannot be a variable so you can't call it in the code. You could have it as...

string path = "{-Project.Directory-}Accounts.txt"
or set it as a project variable in a previous Variable processing action. If you do that then you should use this code to delete all blank lines...

Код:
string[] text = System.IO.File.ReadAllLines(project.Variables["path"].Value).Where(s => s.Trim() != string.Empty).ToArray();
System.IO.File.Delete(project.Variables["path"].Value);
System.IO.File.WriteAllLines(project.Variables["path"].Value, text);
 
  • Спасибо
Реакции: lokiys

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)