MSFN Forum: [Req] Script - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[Req] Script Move file if unique! Rate Topic: -----

#1 User is offline   anthony_field 

  • Group: Members
  • Posts: 8
  • Joined: 18-March 08

Posted 18 March 2008 - 10:09 PM

:thumbup

HEY ALL..

I need a Script or Batch file that can do the following ....

I have say 100 uniquly named files in one directory named ( lock.dat lock1.dat lock2.dat ) and so on...under c:\lock_files\

I need to copy these files to another directory on the same PC c:\lock_upload\

What I need is the script/Batch to move on of the 100 unique files at a time to the destination dir \lock_upload\
buy move it as a new file name lock.dat

then I need the process to wait either a defined time for the next move, or identify if the Lock.dat file exists in the destination dir
then move the next file as lock.dat and so on until all files have been moved as lock.dat to the destination dir.

if no files are left to copy just wait until there is then start again. / or exit .. Until I start it manually again.

I need it like this, as I have 10000 lines of txt that require uploading into a data base, that scans every one min for the lokc.dat file, as the process takes a long time, I split the files up to process them more quickly, but it is entirly painful moving them manually each time.

Please help.


#2 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,118
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 19 March 2008 - 07:14 AM

If the dat files you are copying or the resultant lock.dat file is binary as opposed to ascii (text), then you could use something like this.
@Echo off
If Not Exist C:\lock_files\*.dat Goto :Eof
If Not Exist C:\lock_upload Md C:\lock_upload
Pushd C:\lock_upload
If Exist lock.dat (Copy /b lock.dat + C:\lock_files\*.dat &&(
	Del C:\lock_files\*.dat)) Else (Copy /b C:\lock_files\*.dat lock.dat &&(
	Del C:\lock_files\*.dat))
All you need to do then is schedule the file to run at whatever frequency you require.

You will of course need to ensure that none of the files are in use when you run this.

#3 User is offline   anthony_field 

  • Group: Members
  • Posts: 8
  • Joined: 18-March 08

Posted 19 March 2008 - 02:48 PM

This script works well. Thanks.
But it does not have the ability to move only one of the lock files at a time, and wait until it has been processed, then move the next one.
It appears to over write the the moved lock.dat file in the destination directory.

Can a wait statment be added and if file exists wait until ?

#4 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,118
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 19 March 2008 - 03:28 PM

Perhaps I misunderstood what you were after.

This script appends the content of all files in 'C:\lock_files' with the file extension .dat to a single file named 'C:\lock_upload\lock.dat'

Please try to explain your exact requirements fully again!

#5 User is offline   gunsmokingman 

  • MSFN Addict
  • Group: Super Moderator
  • Posts: 1,991
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 19 March 2008 - 03:54 PM

Try this script just place it in the main folder.
It goes threw the folder every 90 seconds, when it has ran 10 times it will ask you to continuue or quit.
You have to have this folder C:\lock_upload\ or change StrDestination = "C:\lock_upload\" this to
match the end location.

Quote

 Const OverWrite = True
 Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
 On Error Resume Next
 Dim C1, F1, F2, StrDestination, ZZ1
 Set F1 = Fso.GetFolder(".")
  StrDestination = "C:\lock_upload\"
  Do 
   For Each F2 In F1.Files
	If Not F2.Path = WScript.ScriptFullName Then 
	 C1 = C1 +1 
	  Fso.CopyFile F2.Path,StrDestination & F2.Name, OverWrite
	End If
   If C1 = 10 Then
	ZZ1 = MsgBox("Did you want to let the script run for 15 minutes more?",4132,"Quit Or Continue")
	If ZZ1 = 6 Then C1 = 0
	If ZZ1 = 7 Then WScript.quit
   End If  
  '-> Stop The Script For Approx 90 Seconds
   WScript.Sleep 90000	 
   Next
  Loop Until C1 = 10


#6 User is offline   anthony_field 

  • Group: Members
  • Posts: 8
  • Joined: 18-March 08

Posted 19 March 2008 - 04:05 PM

I will try to be clear this time.. Sorry for the confusion..

I have c:\lock_files containing lock.dat lock1.dat lock2.dat ext upto possibly as high as 1000 (sometimes it may only be 100 entries)
these files look like
P|1879006546|C|First last|3yOR|||||300609|2359
P|1879002248|C|First Last|3yOR|||||300609|2359
P|1878002250|C|First Last |Ord|||||300608|2359

Each person starts on a new line.
I do not wish them to append each other on the move.

Now I wish to move these file ( one at a time ) as lock.dat to c:\lock_upload

I need the batch to check to see if the destination file exists, if it does wait a desired amount of time then try again and then try again and so on.
Until all the files in the c:\lock_files are moved successfully.

This Batch file can just loop forever once started.
a majority of the time though, the c:\lock_files directory will not contain any files, in this instance it should just wait until there is files to move.

Hope this covers it all..

I appreciate your assistance.

Thanks

#7 User is offline   anthony_field 

  • Group: Members
  • Posts: 8
  • Joined: 18-March 08

Posted 19 March 2008 - 04:13 PM

Thanks "Gunsmokingman"


Athough I can not seem to run this script...
have saved it as lockscript.bat
It does not seem to run.

Any Ideas ?




Const OverWrite = True
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Dim C1, F1, F2, StrDestination, ZZ1
Set F1 = Fso.GetFolder(".")
StrDestination = "C:\lock_upload\"
Do
For Each F2 In F1.Files
If Not F2.Path = WScript.ScriptFullName Then
C1 = C1 +1
Fso.CopyFile F2.Path,StrDestination & F2.Name, OverWrite
End If
If C1 = 10 Then
ZZ1 = MsgBox("Did you want to let the script run for 15 minutes more?",4132,"Quit Or Continue")
If ZZ1 = 6 Then C1 = 0
If ZZ1 = 7 Then WScript.quit
End If
'-> Stop The Script For Approx 90 Seconds
WScript.Sleep 90000
Next
Loop Until C1 = 10

#8 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,118
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 19 March 2008 - 04:38 PM

It's a VBScript, rename it to lockscript.vbs.

By the name `upload` something must be running already processing the lock.dat file, surely that's being done at a regualr interval so that you can do the same with your script. It is not really efficient to keep the script running indefinitely.

Here's another attempt at supplying you with a batch solution:
MoveDat.cmd
@Echo off&Setlocal
If Exist C:\lock_upload\lock.dat Goto :Eof
for /f "delims=" %%# In ('dir/b/o-d/a-d *.dat') Do Set "%F_%=%%#"
If Not Defined F_ Goto :Eof
Move "%F_%" C:\lock_upload\lock.dat
Place this script into C:\lock_files
I would suggest you just run this file, (say every five minutes, [300 secs]), using Soon.exe from the Windows® 2000 Resource Kit:
soon 300 cmd /c C:\lock_files\MoveDat.cmd


#9 User is offline   anthony_field 

  • Group: Members
  • Posts: 8
  • Joined: 18-March 08

Posted 19 March 2008 - 05:08 PM

Thats Perfect...

Can this VB script Move the file instead of Copy ?

#10 User is offline   anthony_field 

  • Group: Members
  • Posts: 8
  • Joined: 18-March 08

Posted 19 March 2008 - 05:10 PM

sorry last thing...

I need the file to be moved as lock.dat not its original name of lock1.dat and so on...

thanks

#11 User is offline   gunsmokingman 

  • MSFN Addict
  • Group: Super Moderator
  • Posts: 1,991
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 19 March 2008 - 05:20 PM

Ok I added a check to see if the file is not in the end location

Save As WhatEver.vbs

Quote

Const OverWrite = True
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Dim C1, F1, F2, StrDestination, ZZ1
Set F1 = Fso.GetFolder(".")
  StrDestination = "C:\lock_upload\"
  Do 
   For Each F2 In F1.Files
	If Not F2.Path = WScript.ScriptFullName Then 
	 If Not Fso.FileExists(StrDestination & F2.Name) Then 
	  C1 = C1 +1 
	  '-> Uncomment This If You Want To Copy The Original File
	  ' Fso.CopyFile F2.Path,StrDestination & F2.Name, OverWrite
	  '-> This Copies Each File To This Name lock.dat
	   Fso.CopyFile F2.Path,StrDestination & "lock.dat", OverWrite
	 End If 
	End If
   If C1 = 10 Then
	ZZ1 = MsgBox("Did you want to let the script run for 15 minutes more?",4132,"Quit Or Continue")
	If ZZ1 = 6 Then C1 = 0
	If ZZ1 = 7 Then WScript.quit
   End If  
  '-> Stop The Script For Approx 90 Seconds
   WScript.Sleep 90000	 
   Next
  Loop Until C1 = 10


Since I am not sure what you want I have left a Comment out part of the script that will copy the file
as it original name. It set to copy the file as lock.dat

Use this to copy all the files in the parent folder as lock.dat

Quote


'-> Uncomment This If You Want To Copy The Original File
' Fso.CopyFile F2.Path,StrDestination & F2.Name, OverWrite
'-> This Copies Each File To This Name lock.dat
Fso.CopyFile F2.Path,StrDestination & "lock.dat", OverWrite


Use this to copy the file with it original name

Quote


'-> Uncomment This If You Want To Copy The Original File
Fso.CopyFile F2.Path,StrDestination & F2.Name, OverWrite
'-> This Copies Each File To This Name lock.dat
' Fso.CopyFile F2.Path,StrDestination & "lock.dat", OverWrite


This script will overwrite the lock.dat each time it loops threw the collection.
So a move file is not needed.

This post has been edited by gunsmokingman: 19 March 2008 - 05:29 PM


#12 User is offline   anthony_field 

  • Group: Members
  • Posts: 8
  • Joined: 18-March 08

Posted 19 March 2008 - 05:50 PM

I actually need the copied / moved lock.dat to be processed by the server, it then disapears.
then the next file can be moved.

I need the Files that are waiting to be copied/moved to be deleted once successfully

It also seems to move the .vbs script into the _upload folder, when infact I need it to remain in it original folder.

Many Thanks for your help...

Got it...

"Const OverWrite = True
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Dim C1, F1, F2, StrDestination, ZZ1
Set F1 = Fso.GetFolder(".")
StrDestination = "C:\lock_move\"
Do
For Each F2 In F1.Files
If Not F2.Path = WScript.ScriptFullName Then
If Not Fso.FileExists(StrDestination & "lock.dat") Then
C1 = C1 +1
'-> This Copies Each File To This Name lock.dat
Fso.CopyFile F2.Path,StrDestination & "lock.dat", OverWrite
F2.Delete
End If
End If
If C1 = 10 Then
ZZ1 = MsgBox("Did you want to let the script run for 15 minutes more?",4132,"Quit Or Continue")
If ZZ1 = 6 Then C1 = 0
If ZZ1 = 7 Then WScript.quit
End If
'-> Stop The Script For Approx 90 Seconds
WScript.Sleep 10000
Next
Loop Until C1 = 10"

Works Great

This post has been edited by anthony_field: 19 March 2008 - 07:03 PM


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy