Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
space at the end of a filename
kellyrmilligan
I have a perl script that goes through a directory, etc, and manipulates some files. Every once in a great while, I get a file that it can't find, and I see that someone has save the file with a space at the end of the filename.
when I go through the directory, spaces in the filename are fine, but a space at the end kills it. Has anyone dealth with this before besides telling users not to do it? how do I pick this up in my script?
Find more posts tagged with
Comments
Migrateduser
Use a regex to clean up the whitespace. Yawn.
Dave Smith
Sr. Software Engineer
Nike, Inc.
(503) 671-4238
DavidH.Smith@nike.com
gzevin
search google on a phrase 'trim spaces perl'. And there will be a lot of happiness.
Greg Zevin, Ph.D. Comp. Sc.
Independent Interwoven Consultant/Architect
Sydney, AU
JonathonG
Are you quoting the filename before processing it? What are you using to go through the directory? Are you using some kind of trimming routine on the filename? Other replies are suggesting that, but I think that if there is a file that actually ends in a space, trimming the whitespace would
prevent
you from finding it, not help you find it.
Jonathon
Interwoven Developer
Allstate, Inc.
kellyrmilligan
yes, thank you for understanding my post! here's a snippet that I get the files from for processing ,and it is trimming the space at the end of the filename so I am not finding it!!!
opendir(DIR,$useDirectory);
my
@files=readdir(DIR)
;
close(DIR);
and then I just loop through it,and when I process a file in some way, I refer to it as:
# Output this file and path
my $showPath = $useDirectory."/".$file;
if (-d $useDirectory."/".$file){
# It is a directory so you can do any 'directory only' things here
if ($file =~ m/[^(EDITION|STAGING|INITIAL|ed_001)]/i) {
getFiles($useDirectory."/".$file);
}
This just makes sure to recurse through the directories...
then a command on the file would be:
$return = `iwextattr -g TeamSite/Metadata/MT_PROCESS \"$showPath\"`;
Maybe in the way that I am getting filenames, etc?
I start out giving my function the top level of the directory structure, ie
/iwmnt/default/main/bluesource/WORKAREA/Content/templatedata/bluesource/SYSTEM_PROMPT/data
Adam Stoller
Try making the following changes:
# Output this file and path
my $showPath =
"
$useDirectory/$file
"
;
if (-d $
"
showPath
"
){
# It is a directory so you can do any 'directory only' things here
if ($file =~ m/[^(EDITION|STAGING|INITIAL|ed_001)]/i) {
getFiles($useDirectory."/".$file);
}
...
}
I'm striking that inner conditional statment because I'm not sure what you're attempting to do there - but whatever it is, I believe you've written it incorrectly.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
JonathonG
Nothing is jumping out at me from this. A couple more questions that might help debug:
1. How have you determined that the file name ends in a space?
2. What does $showPath look like when printed to a log file? [TIP: when looking for trailing whitespace, I like to add some kind of indicator right after the variable, e.g. print "$showPath<--"
3. Have you tried logging the iwextattr command before executing it? Perhaps the issue isn't in your Perl script, but is actually in the iwextattr processing.
Jonathon
Interwoven Developer
Allstate, Inc.
kellyrmilligan
I tried your suggesting of putting a special character added on to the filename, and I see now that when I am opening the directory:
opendir(DIR,$useDirectory);
my
@files=readdir(DIR)
;
close(DIR);
this is when the space at the end of filename is not making it.
JonathonG
Hmm...that is very strange. What OS? Seems like you may have found either a Perl or OS bug. You may need to try and put in some checking code on the file creation side to prevent this from even happening. To repeat one of my earlier questions, how do you know that the file has a space at the end of the filename? What are you using to deduce that?
Jonathon
Interwoven Developer
Allstate, Inc.
kellyrmilligan
After I run my conversion script, I get an error log that says "could not open file"
I was pretty confused for a while, then just did a file, rename on it in teamsite and noticed there was a space at the end. when I delete the space, and save, it processes fine.
Adam Stoller
Oops - saw a typo in my earlier post - sorry:
if (-d $
"
showPath"){
should be:
if (-d
"
$showPath"){
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
JonathonG
Not sure if you've resolved this, as its been a week, and ghoti's provided a couple of ideas for solving it. If not, what OS are you on? Is there any way you can prevent files from being created with a trailing space?
Jonathon
Interwoven Developer
Allstate, Inc.
kellyrmilligan
I haven't resolved it, and I am not aware of how I would prevent it without some pretty serious formapi coding. Thanks for all the suggestions though.
jbonifaci
Kelly,
I didn't read the post very carefully, but it appears you just want to prevent users from creating DCRs with spaces at the end? This should be fairly easy using the onSaveNameSpecified event handler. You can either strip the space out yourself, or alert the user and abort the save.
~Jeff