Link to home
Start Free TrialLog in
Avatar of david jones
david jones

asked on

Cannot work out how to add to a .VBS script.

Im trying to work out how to add to a . VBS

Script I have so far is shown at bottom.
 
I sort of know how to create a message box but dont know how to run commands if answer "YES or NO" .

What I need is after the file created I need it to ask if it a BTP download. If YES I need it to move to "X:\BTP DOWNLOADS" and then open the folder once moved and then  another message box if poss stating to "ADD STATEMENT AND 7 ZIP/PASSWORD PROTECT FOLDER.

If answer is NO I need it just moved to "X:\CHILTERN DOWNLOADS" again opening folder and a message box starting to "7 ZIP/PASSWORD PROTECT FOLDER."

SCRIPT SO FAR:-

Option Explicit

Const strDLFolder = "C:\Downloads"
Dim objFSO, objWShell, objDLFolder, strNewFolder, objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWShell = CreateObject("WScript.Shell")


If Not objFSO.FolderExists(strDLFolder) Then objFSO.CreateFolder(strDLFolder)
objWShell.CurrentDirectory = strDLFolder
Set objDLFolder = objFSO.GetFolder(strDLFolder)
If objDLFolder.Files.Count = 0 Then WScript.Quit

Do
Err.Clear
strNewFolder = InputBox("Folder Name", vbLf & "Enter the name of the folder to be created:")
If strNewFolder = False Then WScript.Quit
On Error Resume Next
objFSO.CreateFolder strNewFolder
Loop While Err.Number <> 0 Or Not objFSO.FolderExists(strNewFolder)

On Error Goto 0
For Each objFile In objDLFolder.Files
objFSO.MoveFile objFile.Name, strNewFolder & "\"
Next

objWShell.Popup "All files moved.", 0, "Done", vbInformation Or vbSystemModal Or &h00040000&

Open in new window

Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

You just save the choice in a variable
answer = MsgBox ("Yes/No", vbYesNo, "Pick yes or no")

If  answer = vbYes Then
    MsgBox("You picked Yes")
Else
    MsgBox("You picked No")
End If

Open in new window

Avatar of david jones
david jones

ASKER

A big thanks Shaun.,   Ive extremely rusty on .VBS stuff and ive added this to the script to tell it what to do but keep getting the following error and Can I still get the message boxes at the end?

Line 42
Char 5
Name Redefined
800a0411

What ive amended is below..

answer = MsgBox ("Yes/No", vbYesNo, "Pick yes or no")

If  answer = vbYes Then

 
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
 
fso.MoveFolder "X:\CCTV DOWNLOADS", "X:\CCTV DOWNLOADS1\"  

Else
 
Set fso = CreateObject("Scripting.FileSystemObject")
 
fso.MoveFolder "X:\CCTV DOWNLOADS", "X:\CCTV DOWNLOADS2\"

End If
Move this to before the start of the if statement
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Open in new window

Ladies and Gents and especially shaun you have been so helpful and extremely knowledgeable.

I think ive done correct what Shaun said and ive added some new commands but I now get the following error.

line 31
char 1
error Variable is undefined :"answer"
code 800a01f4

Is anyone able to have a read through what I have done and point out any errors so I can amend the text.   Its a true saying that you learn by your mistakes and I certainally am.

Big thanks in advance.

Option Explicit

Const strDLFolder = "X:\CCTV DOWNLOADS"
Dim objFSO, objWShell, objDLFolder, strNewFolder, objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWShell = CreateObject("WScript.Shell")


If Not objFSO.FolderExists(strDLFolder) Then objFSO.CreateFolder(strDLFolder)
objWShell.CurrentDirectory = strDLFolder
Set objDLFolder = objFSO.GetFolder(strDLFolder)
If objDLFolder.Files.Count = 0 Then WScript.Quit

Do
Err.Clear
strNewFolder = InputBox("Folder Name", vbLf & "Enter the name of the folder to be created:")
If strNewFolder = False Then WScript.Quit
On Error Resume Next
objFSO.CreateFolder strNewFolder
Loop While Err.Number <> 0 Or Not objFSO.FolderExists(strNewFolder)

On Error Goto 0
For Each objFile In objDLFolder.Files
objFSO.MoveFile objFile.Name, strNewFolder & "\"
Next

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

answer = MsgBox ("Yes/No", vbYesNo, "Pick yes or no")

If  answer = vbYes Then
 fso.MoveFolder "X:\CCTV DOWNLOADS", "X:\CCTV DOWNLOADS1\"  
x=msgbox("REMEMBER TO ADD STATEMENT AND 7ZIP FILE/PASSWORD" ,0, "MOVE FILES")

Else
fso.MoveFolder "X:\CCTV DOWNLOADS", "X:\CCTV DOWNLOADS2\"
x=msgbox("7ZIP FILE/PASSWORD" ,0, "MOVE FILES")     
End If

Open in new window

You have Option Explicit so you need to add
Dim answer

Open in new window

Thanks for everything,  I done everything on this forum and I now get a invalid procedure ??

LINE 35
CHAR 1
INVALID PROCEDURE CALL OR ARGUMENT
CODE 800a0005

Ive looked and cant see anything that stands out. can anyone shed any light on it?  When I done a count from the top it in the area of FSO.MoveFolder....

On Error Goto 0
For Each objFile In objDLFolder.Files
objFSO.MoveFile objFile.Name, strNewFolder & "\"
Next

answer = MsgBox ("Yes/No", vbYesNo, "Pick yes or no")

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

If  answer = vbYes Then
fso.MoveFolder "X:\Downloads", "X:\Downloads\1234\"  
x=msgbox("REMEMBER TO ADD STATEMENT AND 7ZIP FILE/PASSWORD" ,0, "MOVE FILES")

Else
fso.MoveFolder "X:\Downloads", "X:\Downloads\5678"
x=msgbox("7ZIP FILE/PASSWORD" ,0, "MOVE FILES")    
End If
Don't manually count the lines, open the code in a text editor that has line numbers to be sure which line is in error.  Or post it here which also numbers the lines.

You didn't see the "REMEMBER TO ADD STATEMENT AND 7ZIP FILE/PASSWORD" message, right?

Since you should have added the missing DIM, I'll assume for now that this is the 35th line:

fso.MoveFolder "X:\CCTV DOWNLOADS", "X:\CCTV DOWNLOADS1\"

If so then I would suspect that the folder "X:\CCTV DOWNLOADS1" doesn't already exist, which would throw an error.


»bp
Sorry Bill I thought that it would make no difference.

Heres the script with the numbers below

Im now getting error
 
Line 31
char 1
Variable is undefined "answer"
Code 800a01f4

What you say about "X:\CCTV DOWNLOADS1" its already there but was shown in attributeds in general properties as "read only and ive unticked that.  Also "X" drive is a network drive if that makes any issue but I can merge the files OK so that might be a wild goose chase.

 Option Explicit

Const strDLFolder = "X:\CCTV DOWNLOADS"
Dim objFSO, objWShell, objDLFolder, strNewFolder, objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWShell = CreateObject("WScript.Shell")


If Not objFSO.FolderExists(strDLFolder) Then objFSO.CreateFolder(strDLFolder)
objWShell.CurrentDirectory = strDLFolder
Set objDLFolder = objFSO.GetFolder(strDLFolder)
If objDLFolder.Files.Count = 0 Then WScript.Quit

Do
Err.Clear
strNewFolder = InputBox("Folder Name", vbLf & "Enter the name of the folder to be created:")
If strNewFolder = False Then WScript.Quit
On Error Resume Next
objFSO.CreateFolder strNewFolder
Loop While Err.Number <> 0 Or Not objFSO.FolderExists(strNewFolder)

On Error Goto 0
For Each objFile In objDLFolder.Files
objFSO.MoveFile objFile.Name, strNewFolder & "\"
Next

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

answer = MsgBox ("Yes/No", vbYesNo, "Pick yes or no")

If  answer = vbYes Then
 fso.MoveFolder "X:\CCTV DOWNLOADS", "X:\CCTV DOWNLOADS1\"  
x=msgbox("REMEMBER TO ADD STATEMENT AND 7ZIP FILE/PASSWORD" ,0, "MOVE FILES")

Else
fso.MoveFolder "X:\CCTV DOWNLOADS", "X:\CCTV DOWNLOADS2\"
x=msgbox("7ZIP FILE/PASSWORD" ,0, "MOVE FILES")     
End If

Open in new window

Change this line:

Dim objFSO, objWShell, objDLFolder, strNewFolder, objFile

to:

Dim objFSO, objWShell, objDLFolder, strNewFolder, objFile, answer


»bp
Many Thanks Bill.

Can you confirm but I think that ive got an I.T issue now because they are network drives.  

Im getting

LINE 34
CHARACTER 2
PERMISSION DENIED

Am I right?
Network drives should be fine, assuming you have proper permissions...


»bp
Yeah I though that would a problem.  

I was just just trying to sort an issue I had in a different way but it wont let me have proper permissions so maybe I will be able to get it to work my original way as I know 95% thats fine.
The script below is what I originally had and it was creating folder  and moving files OK no problem.
I was then 7 zipping the folder to password protect it and it was doing that no problem and the folder stayed in C:\DOWNLOADS and once zipped it saved as a Application (.exe) file  and description as 7z SFX.

Trouble comes when I tried to merge a 2nd lot of  files into a new folder in C:\DOWNLOADS. Whats happening is its merging the new files into a folder OK as the first one did but then its also merging the 7 zip folder that I have previously made into it too.
Trouble also is that everytime I merge the files I will have a  application of some description going into folder.

Is there anyway that I can create the folder  but when it moves the files I DO NOT want any folders that are already created and 7zipped merged into it too. I can then password protect afterwards once folder created.  

Original script for creating and merging a file

Option Explicit

Const strDLFolder = "C:\Downloads"
Dim objFSO, objWShell, objDLFolder, strNewFolder, objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWShell = CreateObject("WScript.Shell")


If Not objFSO.FolderExists(strDLFolder) Then objFSO.CreateFolder(strDLFolder)
objWShell.CurrentDirectory = strDLFolder
Set objDLFolder = objFSO.GetFolder(strDLFolder)
If objDLFolder.Files.Count = 0 Then WScript.Quit

Do
Err.Clear
strNewFolder = InputBox("Folder Name", vbLf & "Enter the name of the folder to be created:")
If strNewFolder = False Then WScript.Quit
On Error Resume Next
objFSO.CreateFolder strNewFolder
Loop While Err.Number <> 0 Or Not objFSO.FolderExists(strNewFolder)

On Error Goto 0
For Each objFile In objDLFolder.Files
objFSO.MoveFile objFile.Name, strNewFolder & "\"
Next

objWShell.Popup "All files moved.", 0, "Done", vbInformation Or vbSystemModal Or &h00040000&

Open in new window


What im going to do is set up a VBS where I can move files overnight and I think this is correct.

It moves all files named BTP into "\\crcl.local\ApplicationData\BTPCCTVDownloads" and then moves all remaining files into "S:\CCTV Downloads\CHILTERN DOWNLOADS" and then does a copy also into S:\CCTV Downloads\safety dept

Script below:-

@echo off
PUSHD "C:\CCTV DOWNLOADS\"
FOR "tokens=*" %%A IN ('DIR/B ^| FIND "BTP"') DO MOVE /Y "%%A" "\\crcl.local\ApplicationData\BTPCCTVDownloads"
FOR "tokens=*" %%A IN ('DIR/B') DO MOVE /Y "%%A" "S:\CCTV Downloads\CHILTERN DOWNLOADS"
FOR "tokens=*" %%A IN ('DIR/B') DO COPY /Y "%%A" "S:\CCTV Downloads\safety dept"
exit/b

Open in new window


Sorry to be a pain.

Any Ideas.

Thanks
I don't see where you are creating the 7-zip file so hard to comment about how to adjust your process so that you only zip the 'new' folder.


»bp
In a follow up to our previous posts it seems to work OK with a batch file but not a VBS.  Does anyone know to convert.vbs to batch file if you can??
What would be the exact VBS code that you want implemented in BAT?  Although I don't really see a reason either approach shouldn't work if it is coded properly...  Anything BAT can do VBS should be able to do.

One thing you do have to watch out for though, when you use the MKDIR command in a BAT script (or at the command prompt), ir will create all needed levels of the path that don't exist.  That is not true in VBS when you do fso.CreateFoldr().  It requires all but the final node of the path to already exist as valid folders.  There are ways around that, but not sure if it might be related to problems you are having or not...


»bp
Bill

Im creating the new folder and then im 7 zipping it afterwards myself manually so I can input a different password everytime and tick the create a SFX file box.  

When I go to create a second folder that does it fine and moves data OK but when I go to 7ZIP it thats where the issue is.

I can see where you coming from because im 7zipping it myself thats where the issue is.  

 Dont think I can get it in the  .VBS  to open 7zip and "ADD TO ARCHIVE box appear and then I can do what I need to and password protect .

I think what I need is create a folder and password protect the same way as shown in script below and then it ask me where to move to but as a .BAT FIle ( batch file seem to work OK)  because I can then once moved into new folder I can then 7zip them individually and that should cure it hopefully

Can script be turned into a batch file command?  I think there is a issue with .VBS files and all other files on PC are .BAT files.   Im using windows 7



Option Explicit

Const strDLFolder = "X:\CCTV DOWNLOADS"
Dim objFSO, objWShell, objDLFolder, strNewFolder, objFile, answer

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWShell = CreateObject("WScript.Shell")


If Not objFSO.FolderExists(strDLFolder) Then objFSO.CreateFolder(strDLFolder)
objWShell.CurrentDirectory = strDLFolder
Set objDLFolder = objFSO.GetFolder(strDLFolder)
If objDLFolder.Files.Count = 0 Then WScript.Quit

Do
Err.Clear
strNewFolder = InputBox("Folder Name", vbLf & "Enter the name of the folder to be created:")
If strNewFolder = False Then WScript.Quit
On Error Resume Next
objFSO.CreateFolder strNewFolder
Loop While Err.Number <> 0 Or Not objFSO.FolderExists(strNewFolder)

On Error Goto 0
For Each objFile In objDLFolder.Files
objFSO.MoveFile objFile.Name, strNewFolder & "\"
Next

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

answer = MsgBox ("Yes/No", vbYesNo, "Pick yes or no")

If  answer = vbYes Then
 fso.MoveFolder "X:\CCTV DOWNLOADS", "X:\CCTV DOWNLOADS1\"  
x=msgbox("REMEMBER TO ADD STATEMENT AND 7ZIP FILE/PASSWORD" ,0, "MOVE FILES")

Else
fso.MoveFolder "X:\CCTV DOWNLOADS", "X:\CCTV DOWNLOADS2\"
x=msgbox("7ZIP FILE/PASSWORD" ,0, "MOVE FILES")     
End If

Open in new window

Ladies and Gents

Run the VBS script on my PC at home of which has full administrator rights and still keep getting

LINE 34
CHARACTER 2
PERMISSION DENIED

Any ideas?
Okay, I suspect I see the problem with that now.  Notice in your code you make "X:\CCTV DOWNLOADS" the current working directory when you do:

objWShell.CurrentDirectory = strDLFolder

Then on the line that is erroring out you try to move that directory to a new location:

fso.MoveFolder "X:\CCTV DOWNLOADS", "X:\CCTV DOWNLOADS1\"

Windows won't let you move the directory (or delete it) while it is currently "in use", which it is since you made it the VBS scripts current working directory.  You would need to change to a different working directory before you can move that folder, assuming that's what you want to do.


»bp
AAAHHHH right just so that I get it clear in my head you are saying that cos im trying to move from X:\CCTV DOWNLOADS" into X:\CCTV DOWNLOADS1" it wont let me do it cos they both on same drive.

If I was to save originally to "C\DOWNLOADS" and then move to "X" drive that OK?

The only thing is that I need to know is that after it moved to "X" downloads  will it delete the data in "C\DOWNLOADS" ??
It's not that they are on the same drive, it's that the "X:\CCTV DOWNLOADS" folder is the current working directory for an active process.


»bp
think I got what ya mean will give it a try.

Im trying to be idiot proof here so I understand but what you are saying is that because its using X:\DOWNLOADS as the folder to get stuff from and I when  create a new folder it still saves it to X:\ DOWNLOADS I cant move them cos the .VBS is using "X" drive  to look for everything.

What I need to do is leave "X" drive as the working directory and then when I create a folder I need to save it as something else or do I save to X:\ Downloads and then when folder created move to a different folder in "X" drive and then I can move them?
I'm trying to be idiot proof here so I understand but what you are saying is that because its using X:\DOWNLOADS as the folder to get stuff from and I when  create a new folder it still saves it to X:\ DOWNLOADS I cant move them cos the .VBS is using "X" drive  to look for everything.
It's sort of that, but a little different too.  It isn't just that the VBS wants to read or write (or move) the downloads folder, but rather the fact that you specifically set that as the working folder in the VBS code.  That "locks" that folder from being moved or deleted while the VBS is running.

On the other hand, if you ran the VBS out of a "scripts" directory, let's say c:\scripts, then you could manipulate the downloads directory as long as you specified it's fully qualified path.  You could move or delete it.  I'm not saying that's the best design, just trying to explain the subtle reason the current VBS can't move or delete it.
What I need to do is leave "X" drive as the working directory and then when I create a folder I need to save it as something else or do I save to X:\ Downloads and then when folder created move to a different folder in "X" drive and then I can move them?
Before I respond to this, and since you are also considering a BAT approach, can we take a step back?  Describe in words how you would like this to work, and what you need to happen.  Be complete and accurate, reread it a few times, and then post it.  Based on that I'll try to make some recommendation(s).  Okay?


»bp
A big thanks  and I need it to happen with the following.   I dont care its if a .BAT file or a .VBS as long as I click on a icon on the desktop and it runs automatically .

What it is I receive downloads into the folder  X:\DOWNLOADS.

I click on the ICON.

I then need to create a subfolder with a  message box to appear asking me to input reference number. Once Ive put the reference number in I need it to move all the files from X:\DOWNLOADS into the sub folder that has been created.

After files moved I then need another message box asking me if its  a BTP download  with the YES/NO option.

If I push YES I need it move to folder X:\CCTVDOWNLOADS1   if I push NO I need it moved to folder X:\CCTVDOWNLOADS2

If there data or subfolder still in folder X:\DOWNLOADS after it moved to X:\CCTVDOWNLOADS1  or 2   I need that deleted too but folder X:\DOWNLOADS to remain for when I receive new data.

If I cannot have X:\DOWNLOADS as my original folder for receiving data I can set it as C:\DOWNLOADS as long as it moves it afterwards to X drive and either   downloads1 or 2 depending on what answer is as in YES or NO.

Hope that helps.
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
Bill

You are a legend.     99% there and this maybe was me.   It names and creates the folder no problem and moves no problem.

Slight issue is when it moves the files its not moving the folder too  and files reappear individually X:\CCTVDOWNLOADS1  or 2 and I need them to stay in the folder that was created and named and moved to X:\CCTVDOWNLOADS1  or 2.
It moved the folder in a test here, what did you change in the BAT script, if anything?  And all three of those directories already exist, correct?


»bp
Its OK Bill I have folder as X:\DOWNLOADS on script and as X:\Downloads on PC.

Amended that and it is fine ...  Absolutely perfect.

Thanks
Great.


»bp
Bill

You are a legend  and many many thanks for your patience.

You are a credit to experts exchange and deserve all the points possible.

Thanks
Sorry to be a pain Is there anything else I need to add to get it to move to network drive as downloads ok on “C” drive and set to a network drive and it looses it  when I run the script
Can you be more specific about what you are asking here?  Post the script you are now using, mentioning all changes you made.  And what errors or symptoms are you experiencing that are not acceptable.


»bp
Script below

All ive amended i the access to "X" drive.  it runs ok as far as creating a folder and asking for a password.

When it asks me if a BTP download Y/N when I select either it comes up with "ACCESS DENIED" . When I right click on the folder and use send to "X" drive it does it fine so I believe it not cos im not authorised to go into "X" drive.

Any Ideas?

@echo off
setlocal EnableDelayedExpansion

rem Define folder paths
set BaseDir=C:\DOWNLOADS
set DestDir1=X:\CCTVDOWNLOADS1
set DestDir2=X:\CCTVDOWNLOADS2

rem Quit if no files in download area to process
set Empty=Y
for %%A in ("%BaseDir%\*.*") do set Empty=N
if "%Empty%" EQU "Y" (
    echo No new files to process, quitting.
    exit /b
)

rem Prompt for reference number
set RefNum=
set /P "RefNum=Enter reference number (blank to exit):"

rem If none entered, exit script
if "%RefNum%" EQU "" exit /b

rem Make a subfolder for the reference number
md "%BaseDir%\%RefNum%"

rem Move all files to new subfolder
move "%BaseDir%\*.*" "%BaseDir%\%RefNum%"

rem Ask if BTS download to determine where to move the new folder
choice /C YN /M "Is this a BTP download (Y/N)?"
if !ERRORLEVEL! EQU 1 (
  move "%BaseDir%\%RefNum%" "%DestDir1%"
) else (
  move "%BaseDir%\%RefNum%" "%DestDir2%"
)

rem Remove ALL files from base download folder
del /s /q "%BaseDir%\*.*"

rem Remove any remaining subfolders too
for /d %%A in ("%BaseDir%\*.*") do rd /s /q "%%~A"

Open in new window

Did the new folder you created get moved to the X: drive folder desired?

Are there any other files or folders in the referenced C: folder?


»bp
No other folders in the referenced "C" drive and no new folder didnt get moved to "X" drive.  

When pushed Y/N on the DOS it just cleared the folder from "C" downloads and then come up with "ACCESS DENIED"
If there is no referenc number folder in the X: destination then I would have to think that he following line generated the error, indicating you do not have permissions to create folders in that X: directory.

md "%BaseDir%\%RefNum%"


»bp
Ladies and Gents

Im looking for a slight amendment to the script if poss .

I need it to create a subfolder and ask if it a BTP download Y/N. If I push YES I need it to move to destination directory 1 as per script but If I push NO I need it to ask me if it a chiltern download with Y/N option and if YES I need it moved to destination directory 2 .

If I then push NO can I get it to move the folder to "D" drive so I can burn it to DVD and then remove all files and subfolders as per script.

@echo off
setlocal EnableDelayedExpansion

rem Define folder paths
set BaseDir=X:\DOWNLOADS
set DestDir1=X:\BTP DOWNLOADS
set DestDir2=X:\CHILTERNDOWNLOADS

rem Quit if no files in download area to process
set Empty=Y
for %%A in ("%BaseDir%\*.*") do set Empty=N
if "%Empty%" EQU "Y" (
    echo No new files to process, quitting.
    exit /b
)

rem Prompt for reference number
set RefNum=
set /P "RefNum=Enter reference number (blank to exit):"

rem If none entered, exit script
if "%RefNum%" EQU "" exit /b

rem Make a subfolder for the reference number
md "%BaseDir%\%RefNum%"

rem Move all files to new subfolder
move "%BaseDir%\*.*" "%BaseDir%\%RefNum%"

rem Ask if BTS download to determine where to move the new folder
choice /C YN /M "Is this a BTP download (Y/N)?"
if !ERRORLEVEL! EQU 1 (
  move "%BaseDir%\%RefNum%" "%DestDir1%"
) else (
  move "%BaseDir%\%RefNum%" "%DestDir2%"
)

rem Remove ALL files from base download folder
del /s /q "%BaseDir%\*.*"

rem Remove any remaining subfolders too
for /d %%A in ("%BaseDir%\*.*") do rd /s /q "%%~A"

Open in new window


Thanks
Ok no prob
If it's as simple as this then maybe it's okay as an addition to this closed question, if this isn't it then open a new question please.

@echo off
setlocal EnableDelayedExpansion

rem Define folder paths
set BaseDir=X:\DOWNLOADS
set DestDir1=X:\BTP DOWNLOADS
set DestDir2=X:\CHILTERNDOWNLOADS

rem Quit if no files in download area to process
set Empty=Y
for %%A in ("%BaseDir%\*.*") do set Empty=N
if "%Empty%" EQU "Y" (
    echo No new files to process, quitting.
    exit /b
)

rem Prompt for reference number
set RefNum=
set /P "RefNum=Enter reference number (blank to exit):"

rem If none entered, exit script
if "%RefNum%" EQU "" exit /b

rem Make a subfolder for the reference number
md "%BaseDir%\%RefNum%"

rem Move all files to new subfolder
move "%BaseDir%\*.*" "%BaseDir%\%RefNum%"

rem Ask if BTS download to determine where to move the new folder
choice /C YN /M "Is this a BTP download (Y/N)?"
if !ERRORLEVEL! EQU 1 (
  move "%BaseDir%\%RefNum%" "%DestDir1%"
) else (
  choice /C YN /M "Is this a a chiltern download (Y/N)?"
  if !ERRORLEVEL! EQU 1 (
    move "%BaseDir%\%RefNum%" "%DestDir2%"
  ) else (
    move "%BaseDir%\%RefNum%" "D:\"
  )
)

rem Remove ALL files from base download folder
del /s /q "%BaseDir%\*.*"

rem Remove any remaining subfolders too
for /d %%A in ("%BaseDir%\*.*") do rd /s /q "%%~A"

Open in new window


»bp