我是脚本(或任何类型的编码)的新手。我有一个问题,我想生成csv文件来编目目录和某些文件名,以帮助我的工作。我能够将符合我需要的东西放在一起。除了一个例外,长名称会返回以下错误:
错误:指定的路径,文件名或两者都太长。完全限定的文件名必须少于260个字符,目录名必须少于248个字符。
这是我的剧本:
Write-Host "Andy's File Lister v2.2"
$drive = Read-Host "R or Q?"
$client = Read-Host "What is the client's name as it appears on the R or Q drive?"
$path= "${drive}:\${client}"
Get-ChildItem $path -Recurse -dir | Select-Object FullName | Export-CSV $home\downloads\"$client directories.csv"
Get-ChildItem $path -Recurse -Include *.pdf, *.jp*, *.xl*, *.doc* | Select-Object FullName | Export-CSV $home\downloads\"$client files.csv"
Write-Host "Check your downloads folder."
Pause
正如我所说,我是新手。我可以使用不同的命令,或者告诉脚本跳过一定长度的目录名称或文件吗?
谢谢!
答案 0 :(得分:1)
您可以检查您检查的每个项目的.FullName属性的.Length子属性的值,如果它超过256个字符,请使用Out-Null:
实施例
$items = Get-ChildItem -Path C:\users\myusername\desktop\myfolder
foreach($item in $items)
{
if($item.FullName.Length -lt 256)
{
do some stuff
}
elseif($item.FullName.Length)
{
Out-Null
}
}
如果您还想查看父文件夹的路径,可以查看
$item.Parent.FullName.Length
在你的处理过程中。
答案 1 :(得分:0)
我认为你应该在第5和第6行关闭你的字符串。
您应该使用 private void parseJSon(String data) throws JSONException {
if (data == null)
return;
List<Route> routes = new ArrayList<Route>();
JSONObject jsonData = new JSONObject(data);
JSONArray jsonRoutes = jsonData.getJSONArray("routes");
long totalDistance = 0;
int totalSeconds = 0;
JSONObject jsonDistance = null;
JSONObject jsonDuration = null;
for (int i = 0; i < jsonRoutes.length(); i++) {
JSONObject jsonRoute = jsonRoutes.getJSONObject(i);
Route route = new Route();
JSONObject overview_polylineJson = jsonRoute.getJSONObject("overview_polyline");
JSONArray jsonLegs = jsonRoute.getJSONArray("legs");
for (int j = 0; j < jsonLegs.length(); j++) {
jsonDistance = ((JSONObject) jsonLegs.get(j)).getJSONObject("distance");
totalDistance = totalDistance + Long.parseLong(jsonDistance.getString("value"));
td = String.valueOf(totalDistance);
/** Getting duration from the json data */
jsonDuration = ((JSONObject) jsonLegs.get(j)).getJSONObject("duration");
totalSeconds = totalSeconds + Integer.parseInt(jsonDuration.getString("value"));
ts = String.valueOf(totalSeconds);
double dist = totalDistance / 1000.0;
Log.d("distance", "Calculated distance:" + dist);
int days = totalSeconds / 86400;
int hours = (totalSeconds - days * 86400) / 3600;
int minutes = (totalSeconds - days * 86400 - hours * 3600) / 60;
int seconds = totalSeconds - days * 86400 - hours * 3600 - minutes * 60;
Log.d("duration", days + " days " + hours + " hours " + minutes + " mins" + seconds + " seconds");
}
route.distance = td;
route.duration = ts;
route.points = decodePolyLine(overview_polylineJson.getString("points"));
routes.add(route);
}
listener.onDirectionFinderSuccess(routes);
}
而不是"
,因为目前您的脚本将整个第6行解析为一个字符串。