Link to home
Start Free TrialLog in
Avatar of armstrongnt
armstrongnt

asked on

Vbs script to create Directories and move files to directory

I have bunch of files
0010.txt
001.txt
asd0.txt
0030.txt
0040.txt
0050.txt
vbs script  should create folder structure like this for for every individual file
for 0010.txt
0010 \components
         \notes
         \version
         \workshop\0010_workshop_0001.txt
0010.txt should be copied to 0010 \workshop\ and should be renamed 0010_workshop_0001.txt

the complete path of the file should be  *\0010 \workshop\0010_workshop_0001.txt

IMPORTANT NOTE * represents watever the folder path

one more example fir 0030

0030 \components
         \notes
         \notes
         \workshop\0030_workshop_0001.txt
0010.txt should be copied to 0030 \workshop\ and should be renamed 0030_workshop_0001.txt

the complete path of the file should be  *\0030 workshop\0030_workshop_0001.txt


"components" "notes" "version" Folders are just emply folders which would be used latter on
Avatar of Bill Prew
Bill Prew

This could be done quite easily in a BAT Script, would that be acceptable, or do you require VBS?

~bp
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
Avatar of armstrongnt

ASKER

any thing is acceptable  :)
Thank you....very much
Very welcome, glad to help, thanks.

~bp
+---001
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           001_workshop_0001.txt
            001_workshop_0002.txt
                  001_workshop_0003.txt
                  001_workshop_0004.txt
                  001_workshop_0005.txt
¦
+---0010
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0010_workshop_0001.txt
¦           0010_workshop_0002.txt
¦           0010_workshop_0003.txt
            0010_workshop_0004.txt
            0010_workshop_0005.txt
            0010_workshop_0006.txt
            0010_workshop_0007.txt
            0010_workshop_0008.txt
            0010_workshop_0009.txt
            0010_workshop_0010.txt
            0010_workshop_0011.txt
¦
+---0030
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0030_workshop_0001.txt
            0030_workshop_0002.txt
                  
                  

                  NOW I need a bat file That can copy the last version of the 001.txt(i.e  001_workshop_0005.txt) to its main folder (i.e 001 folder ) and name it has 001_Final.txt
                  
                  The Result should be
+---001
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           001_workshop_0001.txt
            001_workshop_0002.txt
                  001_workshop_0003.txt
                  001_workshop_0004.txt
                  001_workshop_0005.txt
001_Final.txt (this file should be  a copy of 001_workshop_0005.txt )
¦
+---0010
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0010_workshop_0001.txt
¦           0010_workshop_0002.txt
¦           0010_workshop_0003.txt
            0010_workshop_0004.txt
            0010_workshop_0005.txt
            0010_workshop_0006.txt
            0010_workshop_0007.txt
            0010_workshop_0008.txt
            0010_workshop_0009.txt
            0010_workshop_0010.txt
            0010_workshop_0011.txt
0010_Final.txt this file should be  a copy of 0010_workshop_0011.txt )
¦
+---0030
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0030_workshop_0001.txt
            0030_workshop_0002.txt
0030_Final.txt this file should be  a copy of 0030_workshop_0002.txt )
                  
                  
Okay, that's doable, just a minute...

~bp
I think this should do what you asked for.

@echo off
setlocal EnableDelayedExpansion
set BaseDir=c:\Temp\EE26850102
for /D %%A in ("%BaseDir%\*") do (
  if exist "%%A\workshop\" (
    for /F "tokens=*" %%B in ('dir /b /a-d /on "%%A\workshop\*.txt"') do set LastFile=%%B
    copy "%%A\workshop\!LastFile!" "%%A\workshop\%%~nA_Final.txt"
  )
)

Open in new window

~bp
Worked like a charm Thank you very much.. :)
Welcome.

~bp