Solved

Batch File: %%~fA Caracter Count

Posted on 2010-08-16
6
625 Views
Last Modified: 2012-05-10
Hi there,

I need to make a batch file that will count the number of caracters in a FULL PATH.


@echo off
setlocal enabledelayedexpansion

FOR /F "delims=" %%A in ('dir /b /s T:\UsersDocuments\*.*') DO (
  SET FileNumberOfCaractor=[command line to calculate the number of caracters in %%A]
  IF FileNumberOfCaractor GTR 240 ECHO %%A>>FilesToLongList_%date%.txt
)
EXIT


Thanks for your help,
Rene
0
Comment
Question by:ReneGe
  • 3
  • 2
6 Comments
 
LVL 53

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 33448726
Here's a great solution to this problem using a binary search type technique to keep the processing time down.

http://www.dostips.com/DtTipsStringOperations.php#Function.strLen

However in your case, if you just want to know if a string is over 240 in length you should be able to do this:

FOR /F "delims=" %%A in ('dir /b /s T:\UsersDocuments\*.*') DO (
  Set TempA=%%A
  IF "!TempA:~0,240!" NEQ "%%A" ECHO %%A>>FilesToLongList_%date%.txt
)
EXIT

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33448752
Thanks billprew,

Works for me and thanks for the dostips.com link.

Cheers,
Rene
0
 
LVL 11

Expert Comment

by:Ben Personick
ID: 33448799
hey I note you're tyring to find files and directories longer than 255 characters, but your starting path has 19 characters, so you are looking for files and directories over 259 characters in length.


FOR /R T:\ %%A IN (.) DO CALL :Counter "%%A"
GOTO :EOF
:Counter
SET "TPath=%~1"
SET "Count=0"
:Start-Count
SET /A Count=%Count%+1
CALL SET RPath=%%TPath:~0,%Count%%%
IF "%RPath%" NEQ "TPath" GOTO Start-Count
IF %Count% GTR 255 ECHO "%TPath%">>FilesToLongList_%Date%.txt
GOTO :EOF

FOR /R T:\ %%A IN (.) DO CALL :Counter "%%A"
GOTO :EOF
:Counter
SET "TPath=%~1"
SET "Count=0"
:Start-Count
SET /A Count=%Count%+1
CALL SET RPath=%%TPath:~0,%Count%%%
IF "%RPath%" NEQ "TPath" GOTO Start-Count
IF %Count% GTR 255 ECHO "%TPath%">>FilesToLongList_%Date%.txt
GOTO :EOF

Open in new window

0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 11

Expert Comment

by:Ben Personick
ID: 33448812
Nice Code I got caught up in the counting.
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33448852
Thanks QCubed for your script.

It is in deed nice!

I guess I closed the thread to quickly, I would have loved to split the points between you and billprew.

Thanks for everything,
Rene
0
 
LVL 11

Expert Comment

by:Ben Personick
ID: 33448976
no problem.. boblem.. ^^
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question