|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello,
i am newbie in Windows Scripting and I don't know how to solve this problem. I want to move set of *.eml files from one directory to subdirectories. Files have similar names such as: ARCH_2007110100_rest.eml ARCH_2007110100_rest.eml ARCH_2007110101_rest.eml ARCH_2007110102_rest.eml ARCH_2007110200_rest.eml I would like to put file ARCH_2007110100_rest.eml from C:\IMF\Archive\ to C:\IMF\Archive\2007_11\01\00\ where is the 2007_11 year and month (november) and 01 day and 00 hour I would like to put file ARCH_2007110102_rest.eml to C:\IMF\Archive\2007_11\01\02 And file ARCH_2007110200_rest.eml to C:\IMF\Archive\2007_11\02\00 This script will be on server and it will be run periodically on server. Please . |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
"Seiduna" <Seiduna@discussions.microsoft.com> wrote in message
news:447FC472-F640-44A4-B9AB-955BC9828291@microsoft.com... > Hello, > > i am newbie in Windows Scripting and I don't know how to solve this problem. > I want to move set of *.eml files from one directory to subdirectories. > Files have similar names such as: > > ARCH_2007110100_rest.eml > ARCH_2007110100_rest.eml > ARCH_2007110101_rest.eml > ARCH_2007110102_rest.eml > ARCH_2007110200_rest.eml > > I would like to put file ARCH_2007110100_rest.eml from C:\IMF\Archive\ to > C:\IMF\Archive\2007_11\01\00\ > where is the > 2007_11 year and month (november) and > 01 day and > 00 hour > > I would like to put file ARCH_2007110102_rest.eml to > C:\IMF\Archive\2007_11\01\02 > > And file ARCH_2007110200_rest.eml to C:\IMF\Archive\2007_11\02\00 > > > This script will be on server and it will be run periodically on server. > Please . > |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
"McKirahan" <News@McKirahan.com> wrote in message
news:uJ6dnSDIZYuoDK3anZ2dnUVZ_t6onZ2d@comcast.com. .. > "Seiduna" <Seiduna@discussions.microsoft.com> wrote in message > news:447FC472-F640-44A4-B9AB-955BC9828291@microsoft.com... > > Hello, > > > > i am newbie in Windows Scripting and I don't know how to solve this > problem. > > I want to move set of *.eml files from one directory to subdirectories. > > Files have similar names such as: > > > > ARCH_2007110100_rest.eml > > ARCH_2007110100_rest.eml > > ARCH_2007110101_rest.eml > > ARCH_2007110102_rest.eml > > ARCH_2007110200_rest.eml > > > > I would like to put file ARCH_2007110100_rest.eml from C:\IMF\Archive\ to > > C:\IMF\Archive\2007_11\01\00\ > > where is the > > 2007_11 year and month (november) and > > 01 day and > > 00 hour > > > > I would like to put file ARCH_2007110102_rest.eml to > > C:\IMF\Archive\2007_11\01\02 > > > > And file ARCH_2007110200_rest.eml to C:\IMF\Archive\2007_11\02\00 > > > > > > This script will be on server and it will be run periodically on server. > > Please . You have duplicate files listed: > > ARCH_2007110100_rest.eml > > ARCH_2007110100_rest.eml How can that happen? |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
"Seiduna" <Seiduna@discussions.microsoft.com> wrote in message
news:447FC472-F640-44A4-B9AB-955BC9828291@microsoft.com... > Hello, > > i am newbie in Windows Scripting and I don't know how to solve this problem. > I want to move set of *.eml files from one directory to subdirectories. > Files have similar names such as: > > ARCH_2007110100_rest.eml > ARCH_2007110100_rest.eml <<========== duplicate filename > ARCH_2007110101_rest.eml > ARCH_2007110102_rest.eml > ARCH_2007110200_rest.eml > > I would like to put file ARCH_2007110100_rest.eml from C:\IMF\Archive\ to > C:\IMF\Archive\2007_11\01\00\ > where is the > 2007_11 year and month (november) and > 01 day and > 00 hour > > I would like to put file ARCH_2007110102_rest.eml to > C:\IMF\Archive\2007_11\01\02 > > And file ARCH_2007110200_rest.eml to C:\IMF\Archive\2007_11\02\00 > > > This script will be on server and it will be run periodically on server. > Please . How can you have duplicate (ARCH_2007110100_rest.eml) filenames? Unless something else differs in the filename there can only be one file per "hour" and thus only one file in an "hourly" folder. Will this ? It should do what you want. Watch for word-wrap. It only works on ".eml" filenames that contain "_yyyymmddhh_". Option Explicit '* '* Declare Constants '* Const cVBS = "eml_move.vbs" Const cDIR = "C:\IMF\Archive\" Const cDBG = False '* '* Declare Variables '* Dim arrFIL() Dim intFIL intFIL = 0 Dim strFIL Dim strFOL Dim strGF2 Dim intIS1 Dim intIS2 Dim arrMID(3) '* arrMID(0) = yyyy '* arrMID(1) = mm '* arrMID(2) = dd '* arrMID(3) = hh Dim strMID '= yyyymmddhh Dim intMOV intMOV = 0 '* '* Declare Objects '* Dim objDIC Set objDIC = CreateObject("Scripting.Dictionary") Dim objFSO Set objFSO = CreateObject("Scripting.FileSystemObject") Dim objGF1 Set objGF1 = objFSO.GetFolder(cDIR) If Not objFSO.FolderExists(cDIR) Then WScript.Quit Dim objGF2 Set objGF2 = objGF1.Files Dim objOTF '* '* Examine files '* For Each strGF2 In objGF2 strFIL = strGF2.Name intIS1 = InStr(strFIL,"_") intIS2 = InStrRev(strFIL,"_") '* '* Find files with ".eml" extension and "_yyyymmddhh_" '* If LCase(Right(strFIL,4)) = ".eml" _ And intIS2 - intIS1 = 11 Then '* '* Parse "yyyymmddhh" '* strMID = Mid(strFIL,intIS1+1,intIS2-intIS1-1) If cDBG Then WScript.Echo strFIL & " : " & strMID arrMID(0) = Mid(strMID,1,4) arrMID(1) = Mid(strMID,5,2) arrMID(2) = Mid(strMID,7,2) arrMID(3) = Mid(strMID,9,2) '* '* Valid "yyyymmddhh" '* If IsNumeric(strMID) _ And CInt(arrMID(0)) >= 2000 _ And CInt(arrMID(0)) <= DatePart("yyyy",Date) _ And CInt(arrMID(1)) >= 1 _ And CInt(arrMID(1)) <= 12 _ And CInt(arrMID(2)) >= 1 _ And CInt(arrMID(2)) <= 31 _ And CInt(arrMID(3)) >= 0 _ And CInt(arrMID(3)) <= 23 Then '* '* Save folders in dictionary '* strFOL = cDIR & arrMID(0) & "_" & arrMID(1) If Not objDIC.Exists(strFOL) Then objDIC.Add strFOL, strFOL strFOL = strFOL & "\" & arrMID(2) If Not objDIC.Exists(strFOL) Then objDIC.Add strFOL, strFOL strFOL = strFOL & "\" & arrMID(3) If Not objDIC.Exists(strFOL) Then objDIC.Add strFOL, strFOL '* '* Save files in array '* intFIL = intFIL + 1 ReDim Preserve arrFIL(intFIL) arrFIL(intFIL) = strFIL & "," & strFOL & "\" & strFIL End If End If Next '* '* Process files '* If intFIL > 0 Then '* '* Make folders '* For Each strFOL In objDIC If Not objFSO.FolderExists(strFOL) Then If cDBG Then WScript.Echo "objFSO.CreateFolder " & strFOL objFSO.CreateFolder strFOL End If Next '* '* Move files '* For intFIL = 1 To UBound(arrFIL) strFIL = Split(arrFIL(intFIL),",") If cDBG Then WScript.Echo "objFSO.MoveFile " & strFIL(0) & ", " & strFIL(1) objFSO.MoveFile strFIL(0), strFIL(1) intMOV = intMOV + 1 Next End If '* '* Destroy Objects '* Set objDIC = Nothing Set objFSO = Nothing Set objGF1 = Nothing Set objGF2 = Nothing '* '* Completion Message '* MsgBox intMOV & " files moved",vbInformation,cVBS Change the value of "Const cDBG" (debug) to "True" (which will execute the WScript.Echo statements) and run it from the command line to create a log file of script activity; specifically: cscript.exe //nologo eml_move.vbs > eml_move.log |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
"Seiduna" wrote: > Hello, > > i am newbie in Windows Scripting and I don't know how to solve this problem. > I want to move set of *.eml files from one directory to subdirectories. > Files have similar names such as: > > ARCH_2007110100_rest.eml > ARCH_2007110100_rest.eml > ARCH_2007110101_rest.eml > ARCH_2007110102_rest.eml > ARCH_2007110200_rest.eml > > I would like to put file ARCH_2007110100_rest.eml from C:\IMF\Archive\ to > C:\IMF\Archive\2007_11\01\00\ > where is the > 2007_11 year and month (november) and > 01 day and > 00 hour > > I would like to put file ARCH_2007110102_rest.eml to > C:\IMF\Archive\2007_11\01\02 > > And file ARCH_2007110200_rest.eml to C:\IMF\Archive\2007_11\02\00 > > > This script will be on server and it will be run periodically on server. > Please . > Hi, Pls try this, copy the command script below and run in command pormpt. (pls change with your path) ----------------- cmd /v n /c "for /f "usebackq delims=_ tokens=1-3" %a in (`dirC:\IMF\Archive\arch_??????????_rest.eml /b`) do set DT=%b&(if not exist "C:\IMF\Archive\!DT:~0,4!_!DT:~4,2!\!DT:~6,2!\!DT: ~-2!" md "C:\IMF\Archive\!DT:~0,4!_!DT:~4,2!\!DT:~6,2!\!DT: ~-2!")&move %a_%b_%c "C:\IMF\Archive\!DT:~0,4!_!DT:~4,2!\!DT:~6,2!\!DT: ~-2!\"" ----------------- pls note for word wrapping and there is only one line. If you want to save the script as a batch file, pls change %a to %%a, %b to %%b and %c to %%c. Test with some dummy files first. Hope it will you. regards, |
|
![]() |
| Outils de la discussion | |
|
|