Batch file to rename extracted file if same name already exists - command-line

I work for a financial institution that pulls reports from out an outside source. I have an extremely basic batch file that checks folders for any zip file, extracts them to a different location, and moves the zip file to an "old" folder after extraction.
"C:\Program Files\WinZip\WZUNZIP.EXE" -d -o -sXXXXXXXXX C:\SFTP\ReportingAnalytics\Accounting\*.zip \\servername\Share2\Reporting_Analytics\Accounting\
MOVE C:\SFTP\ReportingAnalytics\Accounting\*.zip C:\SFTP\ReportingAnalyticsOld\Accounting
During the week, this works great. The problem is occurring on the weekends. These reports come over daily...unfortunately, with the same file name each day. So during the week, someone is working the report and there is no problem. On the weekends, no one works the report and they are getting overwritten (Friday's report comes in Saturday morning, gets overwritten on Sunday when Saturday's report comes in).
Is there an easy way to automatically rename these files upon extraction? ie AccountingReport1, AccountingReport2, and so on...
Any help would be greatly appreciated.

#ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir\one"
FOR %%a IN ("%sourcedir%\*.zip") DO (
ECHO("C:\Program Files\WinZip\WZUNZIP.EXE" -d -o -sXXXXXXXXX C:\SFTP\ReportingAnalytics\Accounting\%%a \\servername\Share2\Reporting_Analytics\Accounting\%%~na\
)
GOTO :EOF
You would need to change the setting of sourcedir to suit your circumstances.
The required WZUNZIP commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO("...WZUNZIP to "...WZUNZIP to actually create the directories and extract the files.
You don't tell us how many files/directories are in the archive or indicate their names, and your use of -d -o implies there's a whole slough, hence this approach is to extract each .zip file to a new directory, nameofzip under \\servername\S...s\Accounting

Related

ROBOCOPY puts the date 1/1/1980 on some copied files

I am having an intermittent issue with ROBOCOPY copying files with an incorrect date.
I am using ROBOCOPY to copy backup files from a local folder to a remote fileshare as a part of having a remote backup solution. The script is scheduled through task manager to run daily. Here is pseudo code:
ROBOCOPY E:\LocalFolder \\RemoteServer\FileShare\Folder *.bak
Most of the files copy with the correct file date, hovever one or two files sometimes will have the date of 1/1/1980. This presents a major issue with managing the backups in the fileshare because the dates are crucial to its management.
What might causes this?
What can be done to prevent this behavior?
I was having a similar issue. After some searching, I found reference to a behavior of Robocopy where it sets the modified date to 1/1/1980 until after a transfer is completed. [source]
What was really strange in my case was, if I watched the directory during the copy, I would see the file with the correct date appear, then AFTER it was complete the date would change to 1/1/1980. After some experimentation, I removed the /B switch I had been using and the dates seemed to be left alone.

Batch File to Automate backup folders

So, I currently have a Drobo server that houses a Backup folder for customers that need to have their Hard drive files backed up. I create a folder for each customer in this backup folder. It's our policy to keep these files for our customers for 30 days, after which, need to be deleted. I'm wondering if its possible to make a batch file that can scan the entire Backup folder, each folder for each customer ONLY, not all the files, just the folder by modified date and if it is older than 30 days, move the entire folder that I'll label Delete for further review before deleting. I'm going to make a second batch file to delete all the folders and files once inside that delete folder, but I need the first batch file that scans just the folders' modified date in order to determine if it needs moved first. Any help would be appreciated. Thanks.
Forfiles /P C:\test\ /D -30 /c "cmd /c move #file c:/delete"
just an example of script you might use

Execute robocopy powershell continuously between two times established

I have a program that creates temporary files in a specific folder. Then, automatically, after a few seconds, these files are deleted.
I wanted to copy those temporal files to an specific folder, I would like to use a powershell script to do this:
robocopy startFolder destinationFolder *.TIFF *.JPEG *.jpg *.PNG *.GIF *.BMP *.ICO *.PBM *.PGM *.PPM /s /XO
My problem is that I couldn't use a scheduled task (because of the problem with limitation of seconds) or install this powershell as a Windows Service with a powershell script (as far as I know is a bad practice) . I need this powershell running all the time trying to get files at the moment that they are created, before this folders were deleted.
Could you give me a hand please? Thanks!
Not sure it's quite what you want, but robocopy does have directory monitoring funcitonality built-in. You could add /mon:1 which should monitor the source directory and re-run the copy when it detects one change (a new or changed file, for example).
However, a down-side of this perhaps is that using this method, robocopy won't exit - it will run until you kill it.
Edit: I've just noticed you specify in your question title that this should run between two established times, in which case you could add the /rh:hhmm-hhmm option to specify times between which new copies can be started. For example, /rh:1000-1200 should only perform the copies (and hence monitoring) between 10am and midday.
Caveat: I've not tried using the "monitor" option of robocopy, so I'm not sure what sort of delay there would be between a change taking place, and the copy being re-run, but it's worth a shot.

Batch File to move files with the same string of characters into another folder with that string name

I am using Windows 7 Enterprise and have approximately 20 files per day for the last 365 days that I need to sort.
All of the files are in the same directory. Each file name also contains the date of the file's creation. The date is in the format MM-DD-YYY and starts at the 29th character of the file name. The files have the .csv extension.
I need to create a batch file to move all of the files with the same date into their own folder and onto another drive on my computer.
#echo off
setlocal EnableDelayedExpansion
for %%a in (*.csv) do (
set fileName=%%~a
set datePart=!fileName:~28,9!
if not exist "D:\!datePart!" md "D:\!datePart!"
move "%%a" "D:\!datePart!"
)
This script extracts the date part of each file name and uses it as the name of the folder to move the file to. If the folder doesn't exist, it is created, then the file is moved to it.
As written, the script iterates over the .csv files in the current directory. This is specified by the mask in the for loop: *.csv. You can change the mask to include a specific path to process, like C:\path\to\*.csv.
The target drive is also hard-coded and assumed to be D:. Change the corresponding entries of the script if you need to use a different drive.
Detail information on every command used in this script can be obtained by calling the command's built-in help from the command prompt, using either of the below syntaxes:
command /?
help command

Visual SourceSafe 2005 - How to GET changed files for a certain date range (command line tool)

Here I was trying to perform a GET operation to pull a list of files that have been checked in/changed for a given date range, excluding the ones that have not been changed in that time frame.
Here's the command I'm using:
ss Get $\MY_PROJECT to . -Vd8/01/10;12:00a~08/03/10;11:59p -R
In the beginning it actually seems to do what I want - it keeps crunching for a while trying to figure out the files that have changed. Then, all of a sudden, it dumps the remaining non-changed files in the same dir.
Is there a way to achieve what I need? If yes, what's missing? Thanks!
Try this (my vss is on a remote server):
SET SSDIR=\$myserver\myvss\myproject
"C:\Program Files\Microsoft Visual SourceSafe\SS.exe" history $/myproject -Vd31/12/10~17/11/10 -R
Please note that the end date is BEFORE the start date in the range.
I only needed a list of what changes and not the files, that's why I used history.