Batch file - I see 3 different solutions, but how - batch-processing

I am trying to rename and move a file every 120 seconds to a new folder, but in the source folder structure one of the folders is changing every day, the foldername is based on the date.
Example:
MOVE D:\OneDrive\Serienummer\01\2017-03-05\PIC\NVR_ch01*.jpg D:\WEBCAMS\Testkamera\0101.jpg
This works fine, but I need to change the: \2017-03-05\ tomorrow.
To do this manually is not a option!
So is there a way to have a code that will use todays date dynamically?
or
is there a way to grab all files under D:\OneDrive\Serienummer\and move them to the designated new folder location even if the datefolder will change every day?

You can get current year, month, day and have new path every day:
set year=%date:~6,4%
set month=%date:~3,2%
set day=%date:~0,2%
set path = D:\OneDrive\Serienummer\01\%year%-%month%-%day%\PIC\NVR_ch01*.jpg

#echo off
:start
set year=%date:~6,4%
set month=%date:~3,2%
set day=%date:~0,2%
set currentpath = D:\OneDrive\Serienummer\01\%year%-%month%-%day%\PIC\NVR_ch01*.jpg
set targetpath = D:\WEBCAMS\Testkamera\0101.jpg
move %currentpath% %targetpath%
timeout /t 120
goto start
^this finds the date and time and moves the file every 120 seconds until you close cmd

Related

How do I copy files with two properties in AppleScript

I have an external device in my Mac and want to copy the last updated file of this USB-device to my Mac (for example a .PDF or a .jpg). But I have alway an .ini-file (which is alway updated last) on this device and don't want to delete this. I have tried to following code, but it does not work
property source : "Folder A:"
property destination : "Macintosh HD:Users:User:Desktop:Folder B:"
with timeout of (30 * 60) seconds
tell application "Finder"
set the_file to last item of (sort (get files of folder source whose kind ≠ ".INI") by modification date)
copy the_file to folder destination
end tell
end timeout
Another try was to opposite, but it does not work as well
property source : "Folder A:"
property destination : "Macintosh HD:Users:User:Desktop:Folder B:"
with timeout of (30 * 60) seconds
tell application "Finder"
set the_file to last item of (sort (get files of folder source whose kind = ".pdf") by modification date)
copy the_file to folder destination
end tell
end timeout
This following AppleScript code should work for you. Your code was real close. I don’t think it’s necessary to explain what I did because I think it’s obvious by just looking at my version, the few changes that I made.
Sorry about editing your variable names. I took the liberty to rename the variables with what is called “Camel Case”. You can always change them back to your original names if you prefer.
property sourceFolder : "Folder A:" -- The Full Path To This Folder Needs To Be Defined
property destinationFolder : "Macintosh HD:Users:User:Desktop:Folder B:"
property nameExtensions : {"jpg", "pdf"}
with timeout of (30 * 60) seconds
tell application "Finder"
set theFile to last item of (sort (get files of folder sourceFolder ¬
whose name extension is in nameExtensions) by modification date)
copy theFile to folder destinationFolder
end tell
end timeout

External file properties not updated - VBA

I have a macro that reads out external file properties like date created. The file from where I read is stored on a server. Unfortunately the date returned is not the correct one when running the macro the first time. Only when I open the file or when I run the macro several times, the correct updated date created is returned.
Does anyone have an idea how to solve that issue except from opening the file or looping through until the date is correct?
Here is the code:
strFilename = "<FILENAME>"
Workbooks.Open strFilename
Workbooks("strFilename").Close
Set oFS = CreateObject("Scripting.FileSystemObject")
lastcreatedLTVfile = CDate(Format(oFS.GetFile(strFilename).DateCreated, "dd.mm.yyyy"))
Do you want DateCreated or do you actually want DateLastModified? In your question you say "correct updated date" so I guess you should be using DateLastModified.

How to pick the recent file from a location where multiple files are present?

I have a requirement to pickt the latest file from a location. Could any one help me with writing the VB code for this?
Example: I have files like below and their last modified time as below
1. FileDec.txt 2014/12/15 8:35 AM
2. FileJan.txt 2015/01/19 8:34 AM
3. FileNov.txt 2014/01/20 7:48 AM
4. xyz.txt 2015/01/22 8:34 AM
I need to pick FileJan.txt from my shared path(Not xyz.txt). I can not compare file names because of other consrtaint.
Thanks in advance
files is supposed to be some kind of collection of File objects. At the end of the parsing, bestFile should hold the latest file's object.
Dim bestFile as File = Nothing
Dim latest As DateTime
For Each file In files
If (bestFile Is Nothing) Then
bestFile = file
latest = File.GetCreationTime(My.Computer.FileSystem.CombinePath(file.DirectoryName, file.Name))
Else
Dim fileCreatedDate As DateTime = File.GetCreationTime(My.Computer.FileSystem.CombinePath(file.DirectoryName, file.Name))
If (DateTime.Compare(fileCreatedDate, latest) > 0) Then
bestFile = file
latest = fileCreatedDate
End If
End If
Next
I think File.GetCreationTime will give a DateTime, based on which we can do what ever required. Refer below code
Dim fileCreatedDate As DateTime = File.GetCreationTime("C:\Example\MyTest.txt")

Initial Excel Workbook Path

I have an excel spread sheet which, after 30 seconds, saves itself as a new file on the desktop so the original file is not edited. I want the path of the original file, so i add -
"ActiveWorkbook.Path"
But, this doesnt work correctly now, as when the file is saved as a new name after 30 seconds, it takes the
"ActiveWorkbook.Path"
of the newley named file, which in this case is the desktop.
Is there anyway in getting the Path to the initial file, before it got saved ?
I would try to store it in a variable at the start of the code:
Dim originalPath As String
originalPath = ActiveWorkbook.Path
Then, you can refer back to it as needed.

Using one vbscript to change a hard-coded date in another vbscript

I'm working with two related VBscripts right now. The first file calls the second file to perform tasks.
In the second file, I'm constructing several address to create new folders and copy files over. However, the "year" value is hard-coded. Thus I have to manually update it whenever an error in the dates occurs when I run the first file.
For the first file I have, I update the "year" value every week, so that the code is always up to date, but not the second file.
I'm trying to fix the second file by changing the year value to a variable, which will update itself whenever I change the "year" value in the first file.
The part I'm not sure about is how to open the first file within the second file and extract that "year" value in the first file. OR using the first file to open and edit the "year" value in the second file.
If I understood correctly, using named arguments will work.
'First Script
Dim VarYear
VarYear = "2014"
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "second.vbs /passedyear:" & VarYear
'Second Script
Dim PassedYear
PassedYear = WScript.Arguments.Named("passedyear")
MsgBox PassedYear