.BAT文件messure路径长度,并把它放在一个.txt文件 [英] .bat messure file path length and put it in a .txt-file

查看:262
本文介绍了.BAT文件messure路径长度,并把它放在一个.txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让将通过所有文件在指定文件夹中运行.bat文件,测量文件+路径的长度,如果它不是如更长的时间。 50个字符的文件和路径写入到一个.txt文件。

I'm trying to make a .bat file that will run through all files in a given folder, measure the length of the file+path and if its longer than eg. 50 characters the file and path are written into a .txt-file.

我是pretty太大的的n00b,所以不先进,而且有些很好的解释;)

I'm pretty much a n00b, so not to advanced, and somewhat well explained ;).

我写到一个文件中以

回声%文件%> filer.txt

echo %File% > filer.txt

在哪里文件应包含文件名和路径。

Where File should contain the file name and path.

编辑:
对不起,我或许我应该preform任务的描述有点不清楚。我是彪,环槽文件和特定文件夹的子文件夹。并在文档中返回与路径文件超过50,包括驱动器和文件类型。

Im sorry, I was perhaps a bit unclear in my description of the task it should preform. What I ment was, loop trough files and subfolders of a given folder. and return in the document the files with a path longer than 50 including Drive and Filetype.

推荐答案

正如丹尼斯已经指出的,批次具有用于获得该路径的lenght没有内置的溶液。但是,如果你只是想知道,如果一个字符串的长度超过 N ,只检查,如果在一个字符 N + 1 位置:

As Dennis already noted, batch has no built-in solution for getting the lenght of the path. But if you only want to know, if a string is larger than n, just check, if there is a character at the n+1 position:

if "%string:~51,1%" neq "" echo %string% is longer than 50 characters

比计算字符快多了。

Much faster than counting characters.

与丹尼斯的逻辑组合:

@echo off
setlocal EnableDelayedExpansion
(
  for %%g in ("*") do (
    set "File=%%~dpnxg"
    if "!File:~51,1!" neq "" echo !File!
  )
)>filer.txt

我把整个循环到另一块只有一次到输出文件重定向。这是更快(>> 将打开文件,写一行,并关闭文件,只是再次打开它等...)

I put the whole for loop into another block to redirect only once to the output-file. this is much faster (>> would open the file, write one line and close the file, just to open it again etc...)

这篇关于.BAT文件messure路径长度,并把它放在一个.txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆