Link to home
Start Free TrialLog in
Avatar of Rebel_no_1
Rebel_no_1Flag for China

asked on

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

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

Avatar of Bill Prew
Bill Prew

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

~bp
Avatar of Rebel_no_1

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think it is exactly what we need. It works perfectly. Thanks allot Bill.
The solution works exactly in the expected manner. Bill's a champ!
Great, glad that was useful, and thanks for the great feedback!

~bp