Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch File: %%~fA Caracter Count

Posted on 2010-08-16
6
Medium Priority
?
651 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 57

Accepted Solution

by:
Bill Prew earned 2000 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 14
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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
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 …
Progress

715 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