Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   NZ Computing (http://www.velocityreviews.com/forums/f47-nz-computing.html)
-   -   Pgm for finding too long path/filenames. (http://www.velocityreviews.com/forums/t576382-pgm-for-finding-too-long-path-filenames.html)

KiwiBrian 09-09-2005 08:52 AM

Pgm for finding too long path/filenames.
 
I am wanting a program or utility or method of checking a large hierarchy of
folders and files and flagging somehow any that exceed the 255 character
path/filename
limit.
Hoping someone can help
TIA
Brian Tozer



Mercury 09-09-2005 10:37 AM

Re: Pgm for finding too long path/filenames.
 
Nero?
simulate writing a cd.


"KiwiBrian" <briantoz@ihug.co.nz> wrote in message
news:dfrig9$9vg$1@lust.ihug.co.nz...
>I am wanting a program or utility or method of checking a large hierarchy
>of
> folders and files and flagging somehow any that exceed the 255 character
> path/filename
> limit.
> Hoping someone can help
> TIA
> Brian Tozer
>
>




Harry 09-09-2005 11:00 AM

Re: Pgm for finding too long path/filenames.
 
KiwiBrian wrote:

> I am wanting a program or utility or method of checking a large hierarchy
> of folders and files and flagging somehow any that exceed the 255
> character path/filename
> limit.
> Hoping someone can help
> TIA
> Brian Tozer


find /path | awk 'length($0)>255{print $0}'


Hgaoid 09-09-2005 11:08 AM

Re: Pgm for finding too long path/filenames.
 
On Fri, 09 Sep 2005 21:00:03 +1000, Harry <Harry@somewhere.on.the.net> wrote:

>KiwiBrian wrote:
>
>> I am wanting a program or utility or method of checking a large hierarchy
>> of folders and files and flagging somehow any that exceed the 255
>> character path/filename
>> limit.
>> Hoping someone can help
>> TIA
>> Brian Tozer

>
>find /path | awk 'length($0)>255{print $0}'


If you're such a smartarse, you'd check his headers:
Microsoft Outlook Express 6.00.2900.2670

and see your little linux command would do jack.


Mark C 09-09-2005 11:28 AM

Re: Pgm for finding too long path/filenames.
 
Harry <Harry@somewhere.on.the.net> wrote in
news:1296054.pfjB8daAjH@bg.macroshaft.com:

> KiwiBrian wrote:
>
>> I am wanting a program or utility or method of checking a large
>> hierarchy of folders and files and flagging somehow any that
>> exceed the 255 character path/filename
>> limit.
>> Hoping someone can help
>> TIA
>> Brian Tozer

>
> find /path | awk 'length($0)>255{print $0}'


.... or in Windows-speak:

dir c:\/s/b | gawk "length($0)>255{print $0}"

Get gawk here:
http://unxutils.sourceforge.net/

(I note that gawk sometimes doesn't pipe ('|') well on Windows 2000,
so you may have to use this instead:

dir c:/s/b > dir.out
gawk "length($0)>255{print $0}" dir.out

Mark

Graeme Prentice 09-09-2005 11:29 AM

Re: Pgm for finding too long path/filenames.
 
On Fri, 9 Sep 2005 20:52:37 +1200, KiwiBrian wrote:

>I am wanting a program or utility or method of checking a large hierarchy of
>folders and files and flagging somehow any that exceed the 255 character
>path/filename
>limit.
>Hoping someone can help
>TIA
>Brian Tozer
>



Here's a C++ cmd line prog I've hastily modified to do it. It builds a
list then dumps it to the screen. It could write the list to a file if
you prefer. Send me an email if you want the .exe or some slight
changes. It doesn't recurse further when it hits a directory that
already exceeds max length. Builds with GCC. It has some stuff in it
you don't need that I've partly commented out. It might need a
plus/minus one correction somewhere for the length check - or maybe not.

Graeme


#include <string>
#include <cstring>
#include <iostream>
#include <list>
#include <vector>
#include "windows.h"

using std::string;
size_t max_length;

WIN32_FIND_DATA wfd;
std::vector<string> max_list;

inline bool sort_by_name_compare( const WIN32_FIND_DATA& d1,
const WIN32_FIND_DATA& d2)
{
return strcmp( d1.cFileName, d2.cFileName ) < 0;
}

inline bool sort_by_date_compare( const WIN32_FIND_DATA& d1,
const WIN32_FIND_DATA& d2)
{
return CompareFileTime( &d1.ftLastWriteTime, &d2.ftLastWriteTime ) <
0;
}


void display_filename(const WIN32_FIND_DATA & fdat)
{
SYSTEMTIME ftime;
std::cout << "\n " << fdat.cFileName << " ";
if ( FileTimeToSystemTime(&fdat.ftLastWriteTime, &ftime ) )
{
std::cout << ftime.wYear << ' '
<< ftime.wMonth << ' '
<< ftime.wDay << ' '
<< ftime.wHour << ' '
<< ftime.wMinute << ' '
<< ftime.wSecond;
}
}


void FindFiles( string& csStartFolder, bool recurse)
{
static WIN32_FIND_DATA wfd;
static std::list<WIN32_FIND_DATA>::const_iterator filelist_iter;

std::list<WIN32_FIND_DATA> filelist; // for this directory

HANDLE hFF = 0;
string csFile;
string csSubPath;
string csTgt;

csTgt = csStartFolder + "\\*.*";
hFF = FindFirstFile(csTgt.c_str(),&wfd);
if (hFF == INVALID_HANDLE_VALUE)
return;

while (true)
{
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if ( strcmp(wfd.cFileName, ".") &&
strcmp(wfd.cFileName, "..") )
{
csSubPath = csStartFolder + "\\" + wfd.cFileName;
if ( csSubPath.length() >= max_length )
{
max_list.push_back(csSubPath);
}
else if (recurse)
{
FindFiles(csSubPath, recurse);
}
}

/************************************************** *
if ( strcmp(wfd.cFileName, ".") &&
strcmp(wfd.cFileName, "..") && recurse )
{
// recurse into the subdir:
csSubPath = csStartFolder + "\\" + wfd.cFileName;
FindFiles(csSubPath, recurse);
}
************************************************** ***/
}
else
{
csFile = csStartFolder + "\\" + wfd.cFileName;
if ( csFile.length() >= max_length )
{
max_list.push_back(csFile);
}
//filelist.push_back(wfd);
}
if (!FindNextFile(hFF, &wfd))
{
/***********
std::cout << '\n' << csStartFolder << '\n';
std::cout << "\n >>>>> Sorted by name <<<<<";
filelist.sort( sort_by_name_compare );
for ( filelist_iter = filelist.begin();
filelist_iter != filelist.end(); ++filelist_iter )
{
display_filename( *filelist_iter );
}
std::cout << "\n\n >>>>> Sorted by date <<<<<";
filelist.sort( sort_by_date_compare );
for ( filelist_iter = filelist.begin();
filelist_iter != filelist.end(); ++filelist_iter )
{
display_filename( *filelist_iter );
}
*****************/
break;
}
}
FindClose( hFF );
}

int main()
{
string s1;
while (true)
{
std::cout << "\nEnter directory name :";
std::cin >> s1;
std::cout << '\n';
max_length = 100;
if (s1 != "X")
{
max_list.clear();
FindFiles( s1, true);
for (size_t k = 0; k < max_list.size() ;++k )
{
std::cout << max_list[k].length() << ' ' << max_list[k]
<< ' ' << std::endl;
}
}
else
{ break;
}
}
}




Allistar 09-09-2005 11:35 AM

Re: Pgm for finding too long path/filenames.
 
KiwiBrian wrote:

> I am wanting a program or utility or method of checking a large hierarchy
> of folders and files and flagging somehow any that exceed the 255
> character path/filename
> limit.
> Hoping someone can help
> TIA
> Brian Tozer


Hi Brian,
This bash script should do the trick:

=========================
#!/bin/sh

MAX_LEN=255

ls -1R | while read f ; do
length=`expr length "$f"`
if [ $length -gt $MAX_LEN ]; then
echo "$f = $length"
fi
done
=========================

set MAX_LEN to the maximum length you want file names to be, includind their
directory path from the current directory.

Hope this helps,
Allistar.


Harry 09-09-2005 02:17 PM

Re: Pgm for finding too long path/filenames.
 
Hgaoid wrote:

> On Fri, 09 Sep 2005 21:00:03 +1000, Harry <Harry@somewhere.on.the.net>
> wrote:
>
>>KiwiBrian wrote:
>>
>>> I am wanting a program or utility or method of checking a large
>>> hierarchy of folders and files and flagging somehow any that exceed the
>>> 255 character path/filename
>>> limit.
>>> Hoping someone can help
>>> TIA
>>> Brian Tozer

>>
>>find /path | awk 'length($0)>255{print $0}'

>
> If you're such a smartarse, you'd check his headers:
> Microsoft Outlook Express 6.00.2900.2670


If you're such a smartarse then you'd know that gawk is available for
Windows.

If you're such a smartarse then you'd know that Windows filesystems can
be viewed on Linux via Samba.

If you're such a smartarse then you'd know you can boot up Linux and
read Windows filesystems directly.

If you're such a smartarse you'd understand that whatever mail client
somebody uses doesn't mean much. I use OE quite often. But I also
run X with Windows as window manager.

>
> and see your little linux command would do jack.


You are so thick! Read Mark C's post.


Harry 09-10-2005 12:21 PM

Re: Pgm for finding too long path/filenames.
 
KiwiBrian wrote:

> I am wanting a program or utility or method of checking a large hierarchy
> of folders and files and flagging somehow any that exceed the 255
> character path/filename
> limit.
> Hoping someone can help
>


find dir | awk 'length($0)>255{print $0}'


Dave - Dave.net.nz 09-11-2005 09:07 PM

Re: Pgm for finding too long path/filenames.
 
KiwiBrian wrote:
> I am wanting a program or utility or method of checking a large hierarchy of
> folders and files and flagging somehow any that exceed the 255 character
> path/filename
> limit.
> Hoping someone can help


heh, try copying them... it'll tell you.

--
http://dave.net.nz <- My personal site.


All times are GMT. The time now is 01:01 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.