Solved

Batch File: %%~fA Caracter Count

Posted on 2010-08-16
6
638 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 56

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 13
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 13
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 13
ID: 33448976
no problem.. boblem.. ^^
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

623 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