PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.win.server.scripting > Moving files from one directory to subdirectories
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Moving files from one directory to subdirectories

Réponse
 
LinkBack Outils de la discussion
Vieux 06/11/2007, 15h14   #1
Seiduna
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Moving files from one directory to subdirectories

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 .

  Réponse avec citation
Vieux 06/11/2007, 17h06   #2
McKirahan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Moving files from one directory to subdirectories

"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 .
>



  Réponse avec citation
Vieux 06/11/2007, 17h07   #3
McKirahan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Moving files from one directory to subdirectories

"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?


  Réponse avec citation
Vieux 07/11/2007, 01h54   #4
McKirahan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Moving files from one directory to subdirectories

"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



  Réponse avec citation
Vieux 07/11/2007, 06h01   #5
neothwin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: Moving files from one directory to subdirectories



"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 /vn /c "for /f "usebackq delims=_ tokens=1-3" %a in (`dir
C:\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,

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h13.


Édité par : vBulletin® version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17206 seconds with 13 queries