Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Why are my copied filenames being truncated to 8.3 with ~1 ?

Reply
 
Old 11-11-2008   #1 (permalink)
Jason


 
 

Why are my copied filenames being truncated to 8.3 with ~1 ?

Hi

I have written a very simple VBScript that renames a file and copies it to
another folder or server. It works absolutely fine on my XP laptop, on my
W2k3 Server and also my W2K server. However, at the customer site the
resultant files always have a ~1 at the end of the filename. I am using the
standard 'MoveFile' fso method.
Script is below. The customer is running on W2K3 Server, but is only patched
to SP1. Although I don't think that's the problem. In fact I am POSITIVE
there is nothing wrong with the script as it runs fine everywhere else!
eg. Input filename: EEN211P001.eps
output filename should be: "EEN211001" but instead at customer I get
EEN211001~1 !!!??

I have checked the folders/volumes and all are NTFS /etc.
Is there anything in Windows (Registry or security) that would cause this
problem?

Any help greatfully received.
Thanks
Jason

ps. the script is being launched by an application that is feeding it
arguments.

'Purpose:
' It will rename the files by removing any . suffix eg .eps if it exists,
then the last P or M
' It will then copy this file to the destination folder (set the
OutputFolder variable below)
' Typical filename expected eg. "EEN211P001.eps"
' Output should be "EEN211001"

Dim OutputFolder, fso, oArgs
Dim InFileName, OutFileName, FileName, FileName2, logfile
Dim AbsPath

' DEFINE YOUR OUTPUT FOLDER variable BELOW:
' OutputFolder can be any standard windows path (including UNC paths)
' but must be enclosed in double quotes and end in a backslash character "\"
' eg: "C:\Documents and Settings\amhzp\My Documents\_Site
documentation\Scotsman Caledonian\outfolder\"
'
OutputFolder = "C:\Documents and Settings\amhzp\My Documents\_Site
documentation\Scotsman Caledonian\outfolder\"

AbsPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "") 'get
script path
LogFile = AbsPath & "InRename.log" 'put logfile with script

Set fso = CreateObject("scripting.filesystemobject")
Set oArgs = WScript.Arguments
Const ForReading = 1, ForWriting = 2, ForAppending = 8

'First some error checking on the input arguments..
If oArgs.Count = 0 Then
Set logStream = fso.OpenTextFile(LogFile, ForAppending, True)
logStream.WriteLine Now() & " ERROR: No Job argument defined."
logStream.Close
WScript.Quit(1)
End If

InFileName = Ucase(WScript.Arguments(0))

If Len(InFileName) < 3 Or InStr(InFileName, "\") = 0 Then
Set logStream = fso.OpenTextFile(LogFile, ForAppending, True)
logStream.WriteLine Now() & " ERROR: Destination directory incorrectly
defined."
logStream.Close
WScript.Quit(1)
End If

FileName = Right(InFileName, Len(InFileName) - InStrRev(InFileName, "\"))
'extract filename from path
FileName2 = FileName
TextIn = InStr(FileName, ".") 'look to see if there is a suffix
If TextIn Then FileName = Left(FileName, Len(FileName) - (Len(FileName) -
CDbl(TextIn) + 1)) 'if so remove it
FileName = UCase(FileName)
If Mid(FileName, Len(FileName) - 3, 1) = "P" Or Mid(FileName, Len(FileName)
- 3, 1) = "M" Then
FileName = Left(FileName, Len(FileName) - 4) & Right(FileName, 3)
'remove the M or P from new style name
End If

OutFileName = OutputFolder & FileName

On Error Resume Next 'ErrorHandler
If fso.FileExists (OutFileName) Then
fso.DeleteFile (OutFileName)
Set logStream = fso.OpenTextFile(LogFile, ForAppending, True)
logStream.WriteLine now() & " WARNING: Overwriting file " & OutFileName
End If

fso.MoveFile InFileName, OutFileName ' Move the file!

If Err <> 0 Then
Set logStream = fso.OpenTextFile(LogFile, ForAppending, True)
logStream.WriteLine now() & " Input: " & InFileName & " Output: " &
OutFileName
logStream.WriteLine now() & " ERROR: An Error occurred while processing
the above file"
logStream.WriteLine Now() & " ERROR: " & Err.Number & " " &
Err.Description & " " & VbCrLf & _
Now()& " ERROR: Check Directory definitions, logins and available disk
space."
logStream.Close
WScript.Quit(1)
End If


My System SpecsSystem Spec
Old 11-11-2008   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: Why are my copied filenames being truncated to 8.3 with ~1 ?


"Jason" <Jason@xxxxxx> wrote in message
news:7C167585-4643-498D-9B29-B9CBB051BD7A@xxxxxx
Quote:

> Hi
>
> I have written a very simple VBScript that renames a file and copies it to
> another folder or server. It works absolutely fine on my XP laptop, on my
> W2k3 Server and also my W2K server. However, at the customer site the
> resultant files always have a ~1 at the end of the filename. I am using
> the
> standard 'MoveFile' fso method.
> Script is below. The customer is running on W2K3 Server, but is only
> patched
> to SP1. Although I don't think that's the problem. In fact I am POSITIVE
> there is nothing wrong with the script as it runs fine everywhere else!
> eg. Input filename: EEN211P001.eps
> output filename should be: "EEN211001" but instead at customer I get
> EEN211001~1 !!!??
>
> I have checked the folders/volumes and all are NTFS /etc.
> Is there anything in Windows (Registry or security) that would cause this
> problem?
>
> Any help greatfully received.
> Thanks
> Jason
>
> ps. the script is being launched by an application that is feeding it
> arguments.
>
> 'Purpose:
> ' It will rename the files by removing any . suffix eg .eps if it exists,
> then the last P or M
> ' It will then copy this file to the destination folder (set the
> OutputFolder variable below)
> ' Typical filename expected eg. "EEN211P001.eps"
> ' Output should be "EEN211001"
>
> Dim OutputFolder, fso, oArgs
> Dim InFileName, OutFileName, FileName, FileName2, logfile
> Dim AbsPath
>
> ' DEFINE YOUR OUTPUT FOLDER variable BELOW:
> ' OutputFolder can be any standard windows path (including UNC paths)
> ' but must be enclosed in double quotes and end in a backslash character
> "\"
> ' eg: "C:\Documents and Settings\amhzp\My Documents\_Site
> documentation\Scotsman Caledonian\outfolder\"
> '
> OutputFolder = "C:\Documents and Settings\amhzp\My Documents\_Site
> documentation\Scotsman Caledonian\outfolder\"
>
> AbsPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "") 'get
> script path
> LogFile = AbsPath & "InRename.log" 'put logfile with script
>
> Set fso = CreateObject("scripting.filesystemobject")
> Set oArgs = WScript.Arguments
> Const ForReading = 1, ForWriting = 2, ForAppending = 8
>
> 'First some error checking on the input arguments..
> If oArgs.Count = 0 Then
> Set logStream = fso.OpenTextFile(LogFile, ForAppending, True)
> logStream.WriteLine Now() & " ERROR: No Job argument defined."
> logStream.Close
> WScript.Quit(1)
> End If
>
> InFileName = Ucase(WScript.Arguments(0))
>
> If Len(InFileName) < 3 Or InStr(InFileName, "\") = 0 Then
> Set logStream = fso.OpenTextFile(LogFile, ForAppending, True)
> logStream.WriteLine Now() & " ERROR: Destination directory incorrectly
> defined."
> logStream.Close
> WScript.Quit(1)
> End If
>
> FileName = Right(InFileName, Len(InFileName) - InStrRev(InFileName, "\"))
> 'extract filename from path
> FileName2 = FileName
> TextIn = InStr(FileName, ".") 'look to see if there is a suffix
> If TextIn Then FileName = Left(FileName, Len(FileName) - (Len(FileName) -
> CDbl(TextIn) + 1)) 'if so remove it
> FileName = UCase(FileName)
> If Mid(FileName, Len(FileName) - 3, 1) = "P" Or Mid(FileName,
> Len(FileName)
> - 3, 1) = "M" Then
> FileName = Left(FileName, Len(FileName) - 4) & Right(FileName, 3)
> 'remove the M or P from new style name
> End If
>
> OutFileName = OutputFolder & FileName
>
> On Error Resume Next 'ErrorHandler
> If fso.FileExists (OutFileName) Then
> fso.DeleteFile (OutFileName)
> Set logStream = fso.OpenTextFile(LogFile, ForAppending, True)
> logStream.WriteLine now() & " WARNING: Overwriting file " & OutFileName
> End If
>
> fso.MoveFile InFileName, OutFileName ' Move the file!
>
> If Err <> 0 Then
> Set logStream = fso.OpenTextFile(LogFile, ForAppending, True)
> logStream.WriteLine now() & " Input: " & InFileName & " Output: " &
> OutFileName
> logStream.WriteLine now() & " ERROR: An Error occurred while processing
> the above file"
> logStream.WriteLine Now() & " ERROR: " & Err.Number & " " &
> Err.Description & " " & VbCrLf & _
> Now()& " ERROR: Check Directory definitions, logins and available disk
> space."
> logStream.Close
> WScript.Quit(1)
> End If
>
This will happen if you already have a file with a SFN "EEN211001". Run the
command "dir /x" from a Command prompt to see for yourself. Most likely it
has nothing to do with scripting - you would see the same phenomenon if you
used the "copy" command from a Command Shell.


My System SpecsSystem Spec
Old 11-11-2008   #3 (permalink)
Jason


 
 

Re: Why are my copied filenames being truncated to 8.3 with ~1 ?

"Pegasus (MVP)" wrote:
Quote:

>
> This will happen if you already have a file with a SFN "EEN211001". Run the
> command "dir /x" from a Command prompt to see for yourself. Most likely it
> has nothing to do with scripting - you would see the same phenomenon if you
> used the "copy" command from a Command Shell.
>
Thanks for the reply. I don't know what an "SFN" is? "Standard File Name" ?
I can see what you mean with "dir /x" which shows me what the 8.3 version of
the filename is ( or would be), but even when the files with the same name
already exist in the folder I am copying to my script just overwrites them
(without a "~1"), and this works fine on my servers here - I have tested
numerous times, but does not on the customer server.
I really am at a loss..... anyone else??


My System SpecsSystem Spec
Old 11-11-2008   #4 (permalink)
Pegasus \(MVP\)


 
 

Re: Why are my copied filenames being truncated to 8.3 with ~1 ?


"Jason" <Jason@xxxxxx> wrote in message
news:B03822FE-B2E1-428E-A4C7-BC6068DE841A@xxxxxx
Quote:

> "Pegasus (MVP)" wrote:
Quote:

>>
>> This will happen if you already have a file with a SFN "EEN211001". Run
>> the
>> command "dir /x" from a Command prompt to see for yourself. Most likely
>> it
>> has nothing to do with scripting - you would see the same phenomenon if
>> you
>> used the "copy" command from a Command Shell.
>>
>
> Thanks for the reply. I don't know what an "SFN" is? "Standard File Name"
> ?
> I can see what you mean with "dir /x" which shows me what the 8.3 version
> of
> the filename is ( or would be), but even when the files with the same name
> already exist in the folder I am copying to my script just overwrites them
> (without a "~1"), and this works fine on my servers here - I have tested
> numerous times, but does not on the customer server.
> I really am at a loss..... anyone else??
By default Windows maintains two file names for each file:
- Short file names (SFNs), which comply with the 8.3 specification
(up to 8 characters in the name, up to 3 in the extension, no
embedded spaces).
- Long file names (LFNs), which do not comply with the 8.3 specificatiion.

In my previous reply I suggested that your problem is a file system problem,
not a script problem. Did you perform the "copy" test I suggested? What is
the result? If the "copy" command generates in the same problem then you
might be better off posting your question in a "file system" newsgroup where
you find the file system experts.


My System SpecsSystem Spec
Old 11-11-2008   #5 (permalink)
Benny Pedersen


 
 

Re: Why are my copied filenames being truncated to 8.3 with ~1 ?

On Nov 11, 6:08*pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:
Quote:

> "Jason" <Ja...@xxxxxx> wrote in message
>
>
> By default Windows maintains two file names for each file:
> - Short file names (SFNs), which comply with the 8.3 specification
> * *(up to 8 characters in the name, up to 3 in the extension, no
> * *embedded spaces).
> - Long file names (LFNs), which do not comply with the 8.3 specificatiion..
....SNIP...

hmm, strange problem. This one can tell both the SFN and LFN.
Just drag and drop a file or folder onto the thumbnail (icon) of this
VBS file:

' file_info.vbs
dim fso, f
set fso= createObject("scripting.fileSystemObject")

f= wScript.arguments(0)

on error resume next: set f= fso.getFile(f)
if err then set f= fso.getFolder(f)
on error goto 0

inputBox vbLf, "Copy this", f & vbCrLf & f.shortpath

set fso= nothing: set f= nothing
My System SpecsSystem Spec
Old 11-11-2008   #6 (permalink)
Jason


 
 

Re: Why are my copied filenames being truncated to 8.3 with ~1 ?

"Pegasus (MVP)" wrote:
Quote:

>
> By default Windows maintains two file names for each file:
> - Short file names (SFNs), which comply with the 8.3 specification
> (up to 8 characters in the name, up to 3 in the extension, no
> embedded spaces).
> - Long file names (LFNs), which do not comply with the 8.3 specificatiion.
>
> In my previous reply I suggested that your problem is a file system problem,
> not a script problem. Did you perform the "copy" test I suggested? What is
> the result? If the "copy" command generates in the same problem then you
> might be better off posting your question in a "file system" newsgroup where
> you find the file system experts.
>
Thanks for the clarification Pegasus. Yes, I also believe it must be a
filesystem problem now. I have not had the opportunity today to test that on
the clients system, but hopefully will tomorrow. Thanks again for your
replies.. and patience!
Best regards,
Jason
My System SpecsSystem Spec
Old 11-11-2008   #7 (permalink)
Jason


 
 

Re: Why are my copied filenames being truncated to 8.3 with ~1 ?



"Benny Pedersen" wrote:
Quote:

> On Nov 11, 6:08 pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:
Quote:

> > "Jason" <Ja...@xxxxxx> wrote in message
> >
> >
> > By default Windows maintains two file names for each file:
> > - Short file names (SFNs), which comply with the 8.3 specification
> > (up to 8 characters in the name, up to 3 in the extension, no
> > embedded spaces).
> > - Long file names (LFNs), which do not comply with the 8.3 specificatiion..
> ....SNIP...
>
> hmm, strange problem. This one can tell both the SFN and LFN.
> Just drag and drop a file or folder onto the thumbnail (icon) of this
> VBS file:
>
> ' file_info.vbs
> dim fso, f
> set fso= createObject("scripting.fileSystemObject")
>
> f= wScript.arguments(0)
>
> on error resume next: set f= fso.getFile(f)
> if err then set f= fso.getFolder(f)
> on error goto 0
>
> inputBox vbLf, "Copy this", f & vbCrLf & f.shortpath
>
> set fso= nothing: set f= nothing
>
Thanks for the script Benny - very useful. I will test this tomorrow on
client system.
Best regards,
Jason
My System SpecsSystem Spec
Old 11-11-2008   #8 (permalink)
Benny Pedersen


 
 

Re: Why are my copied filenames being truncated to 8.3 with ~1 ?

On Nov 11, 6:49*pm, Jason <Ja...@xxxxxx> wrote:
Quote:

> "Benny Pedersen" wrote:
Quote:

> > On Nov 11, 6:08 pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:
Quote:

> > > "Jason" <Ja...@xxxxxx> wrote in message
>
Quote:
Quote:

> > > By default Windows maintains two file names for each file:
> > > - Short file names (SFNs), which comply with the 8.3 specification
> > > * *(up to 8 characters in the name, up to 3 in the extension, no
> > > * *embedded spaces).
> > > - Long file names (LFNs), which do not comply with the 8.3 specificatiion..
> > ....SNIP...
>
Quote:

> > hmm, strange problem. This one can tell both the SFN and LFN.
> > Just drag and drop a file or folder onto the thumbnail (icon) of this
> > VBS file:
>
Quote:

> > ' file_info.vbs
> > dim fso, f
> > set fso= createObject("scripting.fileSystemObject")
>
Quote:

> > f= wScript.arguments(0)
>
Quote:

> > on error resume next: set f= fso.getFile(f)
> > * if err then set f= fso.getFolder(f)
> > on error goto 0
>
Quote:

> > inputBox vbLf, "Copy this", f & vbCrLf & f.shortpath
>
Quote:

> > set fso= nothing: set f= nothing
>
> Thanks for the script Benny - very useful. I will test this tomorrow on
> client system.
> Best regards,
> Jason- Hide quoted text -
>
> - Show quoted text -

' ok , also try this one:

dim wso: set wso= createObject("wScript.shell")
set fso= createObject("scripting.fileSystemObject")

F= "%TMP%/../\\/hmmm//some.txt and the" & vbCrLf & "OS is: %os%"

F= fso.getAbsolutePathName(wso.expandEnvironmentStrings(F))
msgBox F, 4096


' Benny,
' PS:
'
' Even Microsoft did invented some fatal and detestable path-syntax,
' which don't work with THE ending backslash, I think it would be
' complete unacceptable to specify a path without an ending
' backslash, so below is an update of the previous and ugly one,
' OOPS.
'
' BTW.: Now it also return the current path when double clicked...

' The option explicit most be the first line in script, so remove the
' quote prefix (') from the first line below after testing the above.

'option explicit
dim fso, LFN, f: set fso= createObject("scripting.fileSystemObject")
on error resume next: f= wScript.arguments(0)
err.clear: set f= fso.getFile(f)
if err then
err.clear: set f= fso.getFolder(f)
if err then set f= fso.getFolder(".")
LFN= """" & fso.buildPath(f,"\""")
if len(LFN) = 5 then LFN= replace(LFN,"""","")
f= fso.buildPath(f.shortpath,"\")
else LFN= """" & f & """"
f= uCase(f.shortpath)
end if: on error goto 0
inputBox vbLf, "Copy this", LFN & vbCrLf & f
set fso= nothing: LFN= "": f= ""
My System SpecsSystem Spec
Old 11-11-2008   #9 (permalink)
TDM


 
 

Re: Why are my copied filenames being truncated to 8.3 with ~1 ?


"Jason" <Jason@xxxxxx> wrote in message
news:FABCF414-90F3-4F1F-AC20-9C9E5664D83F@xxxxxx
Quote:

> "Pegasus (MVP)" wrote:
>
Quote:

>>
>> By default Windows maintains two file names for each file:
>> - Short file names (SFNs), which comply with the 8.3 specification
>> (up to 8 characters in the name, up to 3 in the extension, no
>> embedded spaces).
>> - Long file names (LFNs), which do not comply with the 8.3 specificatiion.
>>
>> In my previous reply I suggested that your problem is a file system problem,
>> not a script problem. Did you perform the "copy" test I suggested? What is
>> the result? If the "copy" command generates in the same problem then you
>> might be better off posting your question in a "file system" newsgroup where
>> you find the file system experts.
>>
>
> Thanks for the clarification Pegasus. Yes, I also believe it must be a
> filesystem problem now. I have not had the opportunity today to test that on
> the clients system, but hopefully will tomorrow. Thanks again for your
> replies.. and patience!
> Best regards,
> Jason
This article may help as well, you never know ...

http://support.microsoft.com/kb/121007


TDM


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
UTF encoded filenames cannot be copied Virtual PC
RE: Truncated attachments using WLM Desktop with msn.com Live Mail
Path is being truncated - help! Vista General
Subtitles is truncated Vista music pictures video
DPI/truncated windows Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46