CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
255 characters, long folder path

 



schiffne
New User

Jan 23, 2007, 6:23 AM

Post #1 of 7 (1636 views)
255 characters, long folder path Can't Post

Hi everyone,

I am searching for a pl file which can identify folder strcutures+filename longer then 255 characters. It should have an TXT file as an output like this:


D:\Documents and Settings\Hans Mustermann\My Documents\Eigene Musik\Fredrik Vahle Dietlind Grabe - Glitzerschnee und Knoblauchpizza\Glitzerschnee und Knoblauchpizza\Fredrik Vahle - Dietlind Grabe - Schneefl”ckchen, weiss R”ckchen.mp3
D:\Documents and Settings\Hans Mustermann\My Documents\Eigene Musik\Fredrik Vahle Dietlind Grabe - Glitzerschnee und Knoblauchpizza\Glitzerschnee und Knoblauchpizza\Fredrik Vahle - Dietlind Grabe - Wo wohnt wohl der Weihnachtsmann.mp3


Maybe some of you got an additional problem. I already found the following code, which can do parts of it, but as I am a rookie, it would be great if someone can help me.
Code
#
# *****************************************************************
# Filename: LongPathLocator.pl
# Original Author: Dick Lewis MCSE, MCT, MCP + Internet, A+
# Original Contact: [EMAIL PROTECTED]
# Original Date: 10/04/1999
# Original Purpose: This script is designed capture long paths
# inside the directory structure on a remote sharepoint
# or on a local machine. As paths reach 255 characters and beyond
# users will experience limited accessibily to there data and copy,
# edit, save and delete operations can be impacted negatively.
# The script then builds a series of HTML reports that are
# uniquely named based on the directory name.
# The length of path you want to test for is configurable
# and the reports show the actual length of the path.
# If no files are beyond the configured path threshold then the
# report is still produced but contains a line of text reporting there
# are no long paths detected.
#
# Adapted by: Urs Rau [EMAIL PROTECTED]
# New usage: To report on files which have a path length of over 64 chars
# which is a problem for the freedos booted unattended installer.
#
# First: Install ActivePerl available at [URL=http://www.activestate.com]http://www.activestate.com
# on the computer where the script will run.
#
# CONFIG STEP #1: Enter the target directory where you want to test path length.
# Example: $Target_Directory = "\\\\Seattle\\Sales\\Reports";
#
# CONFIG STEP #2: Enter the path length threshold for testing.
# Example: $Length="200";
#
# CONFIG STEP #3: Configure the report name and location.
# $DIR must be in the report name.
# Example: $OPTFILE = "c:\\TEMP\\output$DIR.html";
#
# This script was tested using:
# ActivePerl build 519 available at [URL=http://www.activestate.com.]http://www.activestate.com.
# Remember to use double \\back slashes
# in your path modifications below. Example: C:\\TestDir\\Fred
# or for a remote path \\\\Fileserver12\\publicshare
# Use this script carefully and test it in a
# non-production environment prior to deployment.
# *****************************************************************
#

use Getopt::Long;
use File::Basename;

# Get the time to put in the report;
$last_updated = localtime (time);

$args = @ARGV;
&GetOptions(\%options, 'dir:s', 'threshold:i', 'prefix:s', 'outdir:s', "help"
=> \$help);
if ($args < 2) {
$help = 1;
}
if ($help) {
die "usage: $0 [-h|--help show this help] -dir z:\\os\\winxppro
[-threshold 64] [-outdir c:\\temp] [-prefix winxppro]\n";
}
# CONFIG STEP #1: Enter the default target directory where you want to test path length.
# Example: $Target_Directory = $options{dir} || "\\\\Seattle\\Sales\\Reports";
$Target_Directory = $options{dir} || "d:\\docume~1";

# CONFIG STEP #2: Enter the default path length threshold for testing.
# Example: $Threshold = $options{threshold} || 200;
$Threshold = $options{threshold} || 64;

# Get the list of directories for directing
# the DIR command and naming the report. Load
# array @DirList with this data.
@DirList = `dir /AD /B $Target_Directory\\*`;
foreach $DIR ( @DirList ) {
# Chomp the $DIR variable to remove newline character.
chomp($DIR);

# Display on screen message on building file list.
print "Building list of files in $dirname directory\n\n";

# Configure the report name prefix and location here.

# CONFIG STEP #3: Report prefix
#
# Example: $OUTFILE = "prefix";
$PREFIX = $options{prefix} || "prefix";

# CONFIG STEP #4: Report directory
#
# Example: $OUTDIR = "$OUTDIR\\$PREFIX-$DIR.html";
$OUTDIR = $options{outdir} || "d:\\web\\";

# CONFIG STEP #5: Configure the report name and location here.
# $DIR must be in the report name.
# Example: $OPTFILE = "c:\\temp\\prefix-$DIR.html";
$OPTFILE = "$OUTDIR\\$PREFIX-$DIR.html";

# Display on screen message that report is being built.
print "Currently writing report to $OPTFILE\n\n";

# Open the output file.
open(OUTPUTFILE, ">$OPTFILE")|| die "open0: $!";

# Initialize the file counter with a blank value
$Counter = 0;

# Build the top of the HTML report containing
# $DIR, $last_updated and $Length variables.
# Escape out Perl reserved characters. Examples: \= and \".
print OUTPUTFILE <<ENDHTML;
<html><head><title>Long Path Report</title></head>
<body BGCOLOR="#FFFFFF" TOPMARGIN="1" LEFTMARGIN="1" ALINK="#666699"
LINK="#336699" vLink="#336699>
<p><font face="Verdana, Arial"><img src="ban_IS.JPG" width="319" height="90"
border="0" alt="Information Systems"></font></p>
<p><big><strong>Long Path Report for $dirname Folder</strong></big></p>
<p><font color="#000000">Last Updated: $last_updated<br>
Path length in</font><font color="#FF0000"> </font><font
color="#000000">--All paths listed over $Threshold characters.</p>
<hr></font><div align="left"><table border="0" width="700" cellspacing="1">
ENDHTML

# Load array with Dir command results on target directory.
# Double quotes prevent DIR command failure due to spaces
# in directory names.
open(DIRCMD, "dir /S /B /A \"$Target_Directory\\$DIR\"\\*|") or die "Unable
to open dir on $DIR.\n";

# For each of the files test length.
while ($File = <DIRCMD>) {
$File =~ /\S/ or next;
chomp($File);

# Extract dirname for $File
$dirname = dirname("$File");

# If length is greater than the configured number.
if (($Length = length($dirname)) > $Threshold) {

# Display on screen path length and path.
print "$Length\t$File\n";

# Increment the counter.
$Counter++;

# Output to file the counter number, length of path
# and full path to file or folder.
print OUTPUTFILE <<ENDHTML;
<tr><td width="710" height="20" align="left">$Counter&nbsp;&nbsp;<font
color="#FF0000">[$Length]</font>&nbsp;&nbsp;$File</td></tr>
ENDHTML

}
}
# If the counter file has not been incremented it indicates
# no long paths were detected and the message needs to be displayed.
unless ($Counter) {

# Print message to screen and output to file.
print "No long file paths over $Threshold characters were detected in the
$dirname folder.\n\n";
print OUTPUTFILE "No long file paths over $Threshold characters were
detected in the $dirname folder.";
}
# Print the final report tags to the output file and close file.
print OUTPUTFILE "</table></div><p>&nbsp;</p></body></html>";
close(OUTPUTFILE) or die "close0: $!";

# Copy the file to the WebReports area.
# rename ("c:\\TEMP\\output_$DIR.html", "d:\\Web\\output$DIR.html");
}




IT would be great if the file can be started like:


LONGFILENAME.pl -source "D:\Documents and Settings" -letters 255 -text c:\test.txt


Thanks for all your help

Marco



davorg
Thaumaturge / Moderator

Jan 23, 2007, 8:28 AM

Post #2 of 7 (1635 views)
Re: [schiffne] 255 characters, long folder path [In reply to] Can't Post

Your current program seems to be making things a lot more difficult than it needs to be!

I think this does what you want.


Code
#!/usr/bin/perl 

use strict;
use warnings;

use Getopt::Long;
use File::Find;
use File::Spec;

my ($len, $src, $out);

GetOptions('source=s', \$src,
'letters=i', \$len,
'text=s', \$out);

open OUT, '>', $out or die "Can't open $out: $!\n";

find(\&do_this, $src);

sub do_this {
my $abs = File::Spec->rel2abs($File::Find::name);
print OUT "$abs\n" if length($abs) > $len;
}


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


schiffne
New User

Jan 23, 2007, 8:48 AM

Post #3 of 7 (1632 views)
Re: [davorg] 255 characters, long folder path [In reply to] Can't Post

Hi,



thanks a lot for your mail. I tried to compile it and getting the error:

Use of uninitialized value in open at D:\test.pl line 14.
Use of uninitialized value in concatenation (.) or string at D:\test.pl line 14

Can't open : No such file or directory



any idea?



Line 14 is open OUT, '>', $out or die "Can't open $out: $!\n";



Thanks

Marco


davorg
Thaumaturge / Moderator

Jan 23, 2007, 9:14 AM

Post #4 of 7 (1631 views)
Re: [schiffne] 255 characters, long folder path [In reply to] Can't Post

Sounds like the value of the output file isn't getting set.

I should point out that because I'm using Getopt::Long, you need to give the program GNU style command line options - i.e. starting with a double dash.


Code
LONGFILENAME.pl --source "D:\Documents and Settings" --letters 255 --text c:\test.txt


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


schiffne
New User

Jan 23, 2007, 11:04 AM

Post #5 of 7 (1628 views)
Re: [davorg] 255 characters, long folder path [In reply to] Can't Post

Hi,



now it works almost perfectly, I am running:

D:\>test.pl --source "D:\Documents and Settings" --letters 255 --text d:\test2.txt

and I got the following result:

D:\Documents and Settings\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.Räuberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und Räuberschmaus\Zwergenspeis und Räuberschmaus kdjfskdf

Now comes the interesting part:

It shows a directory. The thing is that under this directory there are additional files, but Windows XP is not able to show them, because of the 255 character limitation. I

If I use the first code the generated html pages shows:

1 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\02-02D~1.MP3
2 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\02JYDN~4.MP3
3 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\03-03..mp3
4 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\04-04D~1.MP3
5 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\06-06D~1.MP3
6 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\0BZIT9~M.MP3
7 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\0SLYPR~D.MP3
8 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\12-12D~1.MP3
9 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\13-13..mp3
10 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\14-14D.MP3
11 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\15-15..mp3
12 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\1L9TNQ~X.MP3
13 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\23-23D~1.MP3
14 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\2B6JYG~D.MP3
15 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\2TRKQ1~E.MP3
16 [251] d:\Docume~1\Hans Mustermann\My Documents\Eigene Musik\Bernd.Kohlhepp,.Fredrik.Vahle.u.a.-.Zwergenspeis.und.R„uberschmausxxxxxxxxxxxxxxxxxxxxxxxx\Bernd Kohlhepp, Fredrik Vahle u.a - Zwergenspeis und R„uberschmaus\Zwergenspeis und R„uberschmaus kdjfskdf\playlist.m3u


I guess it can only do it because it shortens the Documents and Settings, is there any way to use 8.3 syntax for the whole path?



Thanks again for all your help.



Marco


schiffne
New User

Jan 24, 2007, 4:31 AM

Post #6 of 7 (1623 views)
Re: [davorg] 255 characters, long folder path [In reply to] Can't Post

Hi Dave,



I just figured out that when I run the script on a double byte character machine (japanese) it does not create any text file. Is it possible to support unicode?



Thanks for your help

Marco


davorg
Thaumaturge / Moderator

Jan 24, 2007, 4:35 AM

Post #7 of 7 (1622 views)
Re: [schiffne] 255 characters, long folder path [In reply to] Can't Post


Quote
Is it possible to support unicode?


Almost certainly. But I'm a bit out of my depth when it comes to both Windows filesystems and Unicode. So I'm probably not the best person to help you with this.

You could read perlunicode and if that doesn't help then I recommend asking over at Perl Monks - where they have a wider range of experts.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives