Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 660
  • Last Modified:

Batch File: %%~fA Caracter Count

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
ReneGe
Asked:
ReneGe
  • 3
  • 2
1 Solution
 
Bill PrewCommented:
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
 
ReneGeAuthor Commented:
Thanks billprew,

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

Cheers,
Rene
0
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Nice Code I got caught up in the counting.
0
 
ReneGeAuthor Commented:
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
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
no problem.. boblem.. ^^
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now