Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Vbs script to create Directories and move files to directory

Posted on 2011-02-26
10
Medium Priority
?
346 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:armstrongnt
  • 6
  • 4
10 Comments
 
LVL 59

Expert Comment

by:Bill Prew
ID: 34988857
This could be done quite easily in a BAT Script, would that be acceptable, or do you require VBS?

~bp
0
 
LVL 59

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 34988923
If you wanted to go the BAT rout this should do it.

@echo off
set BaseDir=c:\Temp\EE26850102
for %%A in ("%BaseDir%\*.txt") do (
  md %BaseDir%\%%~nA\components
  md %BaseDir%\%%~nA\notes
  md %BaseDir%\%%~nA\version
  md %BaseDir%\%%~nA\workshop
  copy "%%A" "%BaseDir%\%%~nA\workshop\%%~nA_workshop_0001.txt"
)

Open in new window


This resulted in the following folder and file structure being created:

+---001
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           001_workshop_0001.txt
¦
+---0010
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0010_workshop_0001.txt
¦
+---0030
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0030_workshop_0001.txt
¦
+---0040
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0040_workshop_0001.txt
¦
+---0050
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0050_workshop_0001.txt
¦
+---asd0
    +---components
    +---notes
    +---version
    +---workshop
            asd0_workshop_0001.txt

Open in new window

~bp
0
 

Author Comment

by:armstrongnt
ID: 34988928
any thing is acceptable  :)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Closing Comment

by:armstrongnt
ID: 34988973
Thank you....very much
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 34988980
Very welcome, glad to help, thanks.

~bp
0
 

Author Comment

by:armstrongnt
ID: 34989007
+---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 )
                  
                  
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 34989029
Okay, that's doable, just a minute...

~bp
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 34989123
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
0
 

Author Comment

by:armstrongnt
ID: 34989224
Worked like a charm Thank you very much.. :)
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 34989239
Welcome.

~bp
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

972 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