Discussion:
Help - Archiving specific Extension files
(too old to reply)
Pankaj
2010-09-29 20:53:03 UTC
Permalink
Greetings,

I am not sure if this is correct group or if someone can point me in
right direction

I am currently using Windows Xp (version 2002). I have a requirement
where I need to check a specific directory (not subdirectories) on
Windows for any files with either OLD or NEW extension. If I have
files with these extensions, I need to create a directory with say
today's date and archive all these OLD or NEW extension files to that
newly created directory.

I am currently looking this to be done in Windows Batch scripting. Can
someone please assist here.

TIA
Sam Kidman
2010-09-30 08:39:08 UTC
Permalink
Post by Pankaj
Greetings,
I am not sure if this is correct group or if someone can point me in
right direction
I am currently using Windows Xp (version 2002). I have a requirement
where I need to check a specific directory (not subdirectories) on
Windows for any files with either OLD or NEW extension. If I have
files with these extensions, I need to create a directory with say
today's date and archive all these OLD or NEW extension files to that
newly created directory.
I am currently looking this to be done in Windows Batch scripting. Can
someone please assist here.
TIA
Hello

For what you're trying to do the best scripting language would be
vbscript. batch script is actually severely limited.

pseudocode/vbscript:

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(<path to the folder you want to look at goes
here>)

archiveFolderName = "Archive for " + Date()
fso.CreateFolder(archiveFolderName) //Create the archive folder

Set fileList = f.Files

For Each file In fileList
If (file.Right(3) = "NEW") Or (file.Right(3) = "OLD") Then //
assume the last three characters are the file extension
fso.CopyFile(file, archiveFolderName)
End If
End For

Then I guess you could add a condition to delete the archive folder if
nothing actually gets copied to it. Hope this helps. Let me know if
you have any more questions
Pankaj
2010-09-30 20:00:46 UTC
Permalink
Post by Sam Kidman
Post by Pankaj
Greetings,
I am not sure if this is correct group or if someone can point me in
right direction
I am currently using Windows Xp (version 2002). I have a requirement
where I need to check a specific directory (not subdirectories) on
Windows for any files with either OLD or NEW extension. If I have
files with these extensions, I need to create a directory with say
today's date and archive all these OLD or NEW extension files to that
newly created directory.
I am currently looking this to be done in Windows Batch scripting. Can
someone please assist here.
TIA
Hello
For what you're trying to do the best scripting language would be
vbscript. batch script is actually severely limited.
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(<path to the folder you want to look at goes
here>)
archiveFolderName = "Archive for " + Date()
fso.CreateFolder(archiveFolderName) //Create the archive folder
Set fileList = f.Files
For Each file In fileList
     If (file.Right(3) = "NEW") Or (file.Right(3) = "OLD")  Then //
assume the last three characters are the file extension
         fso.CopyFile(file,  archiveFolderName)
     End If
End For
Then I guess you could add a condition to delete the archive folder if
nothing actually gets copied to it. Hope this helps. Let me know if
you have any more questions- Hide quoted text -
- Show quoted text -
Perfect. Thanks a ton Sam
Pankaj
2010-09-30 20:22:55 UTC
Permalink
Post by Sam Kidman
Post by Pankaj
Greetings,
I am not sure if this is correct group or if someone can point me in
right direction
I am currently using Windows Xp (version 2002). I have a requirement
where I need to check a specific directory (not subdirectories) on
Windows for any files with either OLD or NEW extension. If I have
files with these extensions, I need to create a directory with say
today's date and archive all these OLD or NEW extension files to that
newly created directory.
I am currently looking this to be done in Windows Batch scripting. Can
someone please assist here.
TIA
Hello
For what you're trying to do the best scripting language would be
vbscript. batch script is actually severely limited.
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(<path to the folder you want to look at goes
here>)
archiveFolderName = "Archive for " + Date()
fso.CreateFolder(archiveFolderName) //Create the archive folder
Set fileList = f.Files
For Each file In fileList
     If (file.Right(3) = "NEW") Or (file.Right(3) = "OLD")  Then //
assume the last three characters are the file extension
         fso.CopyFile(file,  archiveFolderName)
     End If
End For
Then I guess you could add a condition to delete the archive folder if
nothing actually gets copied to it. Hope this helps. Let me know if
you have any more questions- Hide quoted text -
- Show quoted text -
Sam, quick question. This will be called by a parent program. If there
was any error in Copying any files, we need to report this to the
called program. Is there a error checking in Copy (or Move) function
that can tell called program that it was either success or failure?

TIA
Sam Kidman
2010-10-01 08:23:12 UTC
Permalink
Post by Pankaj
Sam, quick question. This will be called by a parent program. If there
was any error in Copying any files, we need to report this to the
called program. Is there a error checking in Copy (or Move) function
that can tell called program that it was either success or failure?
TIA
Not sure about this, I think theirs only two errors that could happen
during the copy:

- out of hard disk space
- something really bad happening to the hard drive

In those cases, the copyfile method would return zero.

see here: http://msdn.microsoft.com/en-us/library/aa363851%28VS.85%29.aspx

As for checking file integrity- i think this is the job of the
filesystem and underlying hard drive. You could check the file byte by
byte against the original, but if you don't trust the hard drive in
the first place, what's the point?

Given that this is going to be called from a master program, it should
stop executing as soon as an error in copying occurs, as chances are
the cause of the error will prevent any further copying. the copying
program should also report which filename failed to copy.

For Each file In fileList
If (file.Right(3) = "NEW") Or (file.Right(3) = "OLD") Then
If (fso.CopyFile(file, archiveFolderName) Then //If copying
fails
errorFile = file
Exit For // break out of for loop
End If
End For

If Not errorFile = "" Then
//pass an error up to the master program here with the file name
End If

Regards, Sam
Sam Kidman
2010-10-01 10:51:22 UTC
Permalink
         If (fso.CopyFile(file,  archiveFolderName) Then
should be
If Not (fso.CopyFile(file, archiveFolderName) Then
Al Dunbar
2010-10-02 00:10:39 UTC
Permalink
Post by Sam Kidman
Post by Sam Kidman
If (fso.CopyFile(file, archiveFolderName) Then
should be
Post by Sam Kidman
If Not (fso.CopyFile(file, archiveFolderName) Then
unmatched quotes. try this instead:

If Not (fso.CopyFile(file, archiveFolderName) ) Then

/Al
Al Dunbar
2010-10-02 03:58:53 UTC
Permalink
Post by Al Dunbar
Post by Sam Kidman
Post by Sam Kidman
If (fso.CopyFile(file, archiveFolderName) Then
should be
Post by Sam Kidman
If Not (fso.CopyFile(file, archiveFolderName) Then
Stupid man, Al, surely you meant "unmatched parentheses"...
Post by Al Dunbar
If Not (fso.CopyFile(file, archiveFolderName) ) Then
/Al
Sam Kidman
2010-10-02 17:46:20 UTC
Permalink
Post by Pankaj
Sam, quick question. This will be called by a parent program. If there
was any error in Copying any files, we need to report this to the
called program. Is there a error checking in Copy (or Move) function
that can tell called program that it was either success or failure?
TIA
 Not sure about this, I think theirs only two errors that could happen
- out of hard disk space
- something really bad happening to the hard drive
In those cases, the copyfile method would return zero.
see here:http://msdn.microsoft.com/en-us/library/aa363851%28VS.85%29.aspx
As for checking file integrity- i think this is the job of the
filesystem and underlying hard drive. You could check the file byte by
byte against the original, but if you don't trust the hard drive in
the first place, what's the point?
Given that this is going to be called from a master program, it should
stop executing as soon as an error in copying occurs, as chances are
the cause of the error will prevent any further copying. the copying
program should also report which filename failed to copy.
For Each file In fileList
     If (file.Right(3) = "NEW") Or (file.Right(3) = "OLD")  Then
         If (fso.CopyFile(file,  archiveFolderName) Then //If copying
fails
            errorFile = file
            Exit For // break out of for loop
     End If
End For
If Not errorFile = "" Then
//pass an error up to the master program here with the file name
End If
Regards, Sam
I would also like to point out that while that reference is for the C+
+ version of CopyFile, the actual binary of the function is the same-
same .dll, same parameters. the result and return value is the same.
contrex
2010-10-03 06:59:40 UTC
Permalink
Post by Sam Kidman
archiveFolderName = "Archive for " + Date()
You don't concatenate strings with a + in vbscript, and if the date
string format set by locale settings includes slashes, you'll have an
illegal filename.
Al Dunbar
2010-10-03 16:17:19 UTC
Permalink
Post by contrex
Post by Sam Kidman
archiveFolderName = "Archive for " + Date()
You don't concatenate strings with a + in vbscript, and if the date
string format set by locale settings includes slashes, you'll have an
illegal filename.
While I agree that it is better to concatenate strings with "&", the
addition operator will, in some cases perform a concatenation. Try this:

msgbox "12" + "34"

the result I get is "1234", rather than 46. Of course, the results are less
predictable and consistent when the values operated on are contained in
variables...

/Al

Loading...