Du meinst? :Diese Dateien sollen in Ordner Verschoben werden:
123456 beliebiger Text
141166 beliebiger Text
Code: Select all
123456
141166
Code: Select all
If WScript.arguments.Count < 1 Then
WScript.Echo "Parameter missing!"& VbCrLf & VbCrLf &_
"Command : MoveFiles2SubFolders(matching).vbs"& VbCrLf &_
"Parameters: ""%L"" 1 -4"& VbCrLf &_
"Tooltip : move all marked files into matching (N characters) subfolders"& VbCrLf & VbCrLf &_
" # first parameter: %L :Name of a list file with long file names including the complete path"& VbCrLf & VbCrLf &_
" # second parameter (opt): 1 :start position to find matching"& VbCrLf &_
" # third parameter (opt): 4 :number of characters to match"& VbCrLf &_
" negative value to supress expected messages ""Destination File exists (skipped)!"" "
WScript.Quit
End If
Const FOR_READING = 1
Const cNotFound = "Not Found!"
nStart = 1
nLength = 4
sFileList = WScript.arguments.Item( 0 )
bSilent = false
If WScript.arguments.Count > 1 Then
nStart = abs( WScript.arguments.Item( 1 ) )
End If
If WScript.arguments.Count > 2 Then
If WScript.arguments.Item( 2 ) < 0 Then bSilent = true
nLength = abs( WScript.arguments.Item( 2 ) )
End If
Set oFSO = CreateObject( "Scripting.FileSystemObject" )
If oFSO.FileExists(sFileList) Then
Set oTextStream = oFSO.OpenTextFile( sFileList, FOR_READING )
Do Until oTextStream.AtEndOfStream
sFilePathName = oTextStream.ReadLine
If oFSO.FileExists( sFilePathName ) Then
sPath = oFSO.GetParentFolderName( sFilePathName )
sName = oFSO.GetBaseName( sFilePathName )
sExtension = oFSO.GetExtensionName( sFilePathName )
sPattern = Trim(Mid( sName, nStart, nLength ))
sMatchingFolder = MatchingFolder( sPath, sPattern )
If sMatchingFolder = cNotFound Then
answer = MsgBox ( "No matching Destination Folder found!" & VbCrLf & _
sFilePathName & VbCrLf & VbCrLf & _
"Do You want to create a new Folder?" & VbCrLf & VbCrLf & _
sPattern, vbYesNo + vbQuestion )
If answer = vbYes Then
sMatchingFolder = sPath & "\" & sPattern
oFSO.CreateFolder( sMatchingFolder )
End If
End If
If Not sMatchingFolder = cNotFound Then
sNewFilePathName = sMatchingFolder & "\" & sName & "." & sExtension
If Not oFSO.FileExists( sNewFilePathName ) Then
oFSO.MoveFile sFilePathName, sNewFilePathName
ElseIf Not bSilent Then
WScript.Echo "Destination File exists (skipped)!: " & VbCrLf & sNewFilePathName
End If
ElseIf Not bSilent Then
WScript.Echo "No matching Destination Folder found!" & VbCrLf & sFilePathName
End if
End If
Loop
oTextStream.Close
Else
WScript.Echo "Input file list " & sFileList & " not found."
End If
Function MatchingFolder(sPath,sPattern)
set oFolder = oFSO.GetFolder(sPath)
set oSubFolders = oFolder.SubFolders
For Each oFolder in oSubFolders
If oFolder.name = sPattern Then
MatchingFolder = sPath & "\" & oFolder.Name
Exit Function
End If
Next
MatchingFolder = cNotFound
End Function
Code: Select all
"%L" 9 6
Ich habe im Code ein paar Veränderungen vorgenommen, darum als Hinweis:
Die relevante Änderung ist die Benutzung von Mid(string,start,count) anstelle von Left(string,count)
Wie immer:
Erst an Beispieldateien testen, bevor du den Script auf wichtige Dateien loslässt.
Gruß
Holger