Solved

Dos bat Script to loop through files with a -0.7z suffix.

Posted on 2014-01-22
6
499 Views
Last Modified: 2014-01-22
The only difference between this script and this one is that the one works with a folder name and the one I need now needs to work with a file name.

So far the script looks like this. I know it cannot be completely wrong.

::@echo off
:DATAAVAILABILITYCHECK

setlocal enabledelayedexpansion
IF EXIST D:\DATA\ SET DataFile=D:\DATA\
IF EXIST E:\DATA\ SET DataFile=E:\DATA\
IF EXIST F:\DATA\ SET DataFile=F:\DATA\
IF EXIST G:\DATA\ SET DataFile=G:\DATA\
IF EXIST H:\DATA\ SET DataFile=H:\DATA\


setlocal enabledelayedexpansion
for /f %%a in ("%DataFile%") do (
	set FolderName=%%~nxa
	if /i "!FolderName:~-5!"=="-0.7z" (
		set ProcessFolder=%%~a
		goto :DATASETSTART
	)
)
CLS
ECHO NO DATA SETS DETECTED...
PAUSE
CLS
GOTO :DATAAVAILABILITYCHECK


:DATASETSTART
ECHO FILE DETECTED AS %ProcessFolder%...
::SCRIPT WILL BE IN HERE AND PERFORM ACTIONS WITH %ProcessFolder%
::ONCE ACTIONS IS FINISHED THE SUFFIX WILL BE CHANGED FROM "-0" to "-1"
::WHEN THE SCRIPT IS FINISHED IT WILL GOTO :DATAAVAILABILITYCHECK

Open in new window

0
Comment
Question by:Rebel_no_1
  • 3
  • 3
6 Comments
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
So, are there folders under the DATA directory, or do you just want to process any matching files within that one folder?

~bp
0
 

Author Comment

by:Rebel_no_1
Comment Utility
There is no folders inside the DATA directory. Only files with a file name similar to these:
ECN-0601-VRK__2014-01-22__20h43-0.7z
ECN-0604-VRK__2014-01-01__10h43-0.7z
ECN-0702-VRK__2014-01-22__10h43-0.7z
ECN-0904-VRK__2014-01-31__10h43-0.7z

The idea is to process them one by one. After they are processed the suffix will change from "-0" to "-1".

Therefore, if the above four files have been processed their names will be:
ECN-0601-VRK__2014-01-22__20h43-1.7z
ECN-0604-VRK__2014-01-01__10h43-1.7z
ECN-0702-VRK__2014-01-22__10h43-1.7z
ECN-0904-VRK__2014-01-31__10h43-1.7z

Hope this helps to clarify the scripts intended operation.
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
I think this should be pretty close to what you need, let me know what questions you have.

@echo off
setlocal EnableDelayedExpansion

:DataAvailabilityCheck

set DataFile=
for %%A in (D,E,F,G,H) do (
  if exist %%A:\DATA\ set DataFile=%%A:\DATA\
)

if "%DataFile%" EQU "" (
    REM *** NOT SURE WHAT YOU WANT TO DO UNDER THIS CONDITION ***
    echo No data file folder could be located
    exit /b
)

set FileCount=0
for %%A in ("%DataFile%*-0.7z") do (
    set /a FileCount+=1
    set FileName=%%~nxA
    echo Processing file: "%%~A"
    REM *** DO ANY PROCESSING HERE ***
    ren "%%~A" "!FileName:-0.7z=-1.7z!"
)

cls
Processed [%FileCount%] files.
goto :DataAvailabilityCheck

Open in new window

~bp
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Rebel_no_1
Comment Utility
I think it is exactly what we need. It works perfectly. Thanks allot Bill.
0
 

Author Closing Comment

by:Rebel_no_1
Comment Utility
The solution works exactly in the expected manner. Bill's a champ!
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Great, glad that was useful, and thanks for the great feedback!

~bp
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now