Solved

Batch File: %%~fA Caracter Count

Posted on 2010-08-16
6
616 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 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
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
Comment Utility
Thanks billprew,

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

Cheers,
Rene
0
 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 11

Expert Comment

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

Author Comment

by:ReneGe
Comment Utility
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
Comment Utility
no problem.. boblem.. ^^
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now