Page 1 of 1

can I have a script in same folder as where merging from

Posted: 03 Aug 2018 13:39
by tweacle
I have this script of which is saved with the name merge.bat and it is also in X:\DOWNLOADS of which is where data im getting is also located. When im merging up files its also merging the .bat script.

1) Can I have a bat script in same folder as where getting data from?

2) If so is there anyway the script can be amended to merge as stated below but ignore the .bat file so I can click on it next time for when I want to merge again .

Thanks

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem Define folder paths
set BaseDir=X:\DOWNLOADS

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 Ask if BTP download to determine 
set Download=
choice /C YN /M "Is this a BTP download (Y/N)?"
if !ERRORLEVEL! EQU 1 (
  set Download=BTP
) else (
  choice /C YN /M "IS THIS A CHILTERN DOWNLOAD(Y/N)?"
  if !ERRORLEVEL! EQU 1 (
    set Download=CHILTERN
  )
)

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%\%Download%%RefNum%"

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

Select all
 
Open in new window

Re: can I have a script in same folder as where merging from

Posted: 03 Aug 2018 13:47
by Squashman
Instead of using the MOVE command, use ROBOCOPY and use the exclude file and move options that ROBOCOPY has.

Re: can I have a script in same folder as where merging from

Posted: 04 Aug 2018 10:13
by tweacle
Please correct me if im wrong I know that robocopy copies and you can do various things but I am creating a new subfolder with a particular reference number and 3 letters depending on how I answer.

Robocopy would not work when moving files would it as ive created a sub folder and named it?

Re: can I have a script in same folder as where merging from

Posted: 04 Aug 2018 11:10
by Squashman
tweacle wrote:
04 Aug 2018 10:13
Please correct me if im wrong I know that robocopy copies and you can do various things but I am creating a new subfolder with a particular reference number and 3 letters depending on how I answer.

Robocopy would not work when moving files would it as ive created a sub folder and named it?
I don't see how you think that is valid logic. You are first using the MD command to make your target directory and then using that target directory in your move command. It would be no different then using the target directory with literally ANY command that you can define the target directory.

Re: can I have a script in same folder as where merging from

Posted: 04 Aug 2018 11:55
by tweacle
Please accept my apologies but im confused.

Im totally new to robocopy and only know how to do it by using an app online called robocopy and that is so simple as in copying from one drive to another with all commands.

When it comes to other things its all above my head. I really wanna learn but aint got a clue. I i know im asking a lot but is there any chance anyone could amend the script I supplied and explain how you come to the new end.

Big thanks in advance

Re: can I have a script in same folder as where merging from

Posted: 04 Aug 2018 12:31
by Squashman
tweacle wrote:
04 Aug 2018 11:55
Please accept my apologies but im confused.

Im totally new to robocopy and only know how to do it by using an app online called robocopy and that is so simple as in copying from one drive to another with all commands.
Not True. You were given ROBOCOPY code in this question
tweacle wrote:
04 Aug 2018 11:55
When it comes to other things its all above my head. I really wanna learn but aint got a clue. I i know im asking a lot but is there any chance anyone could amend the script I supplied and explain how you come to the new end.
But that seems to be the same things you say to me in a lot of your threads. I would really expect you to at least make an attempt first. The syntax is not that hard to understand

Code: Select all

ROBOCOPY source destination [files to copy] [options you want to use]
So plug in those four options into that template.
1. Source - The folder with your files
2. Destination - The folder where you want the files to go.
3. Files to Copy - The files you want to copy. Wildcards can be used
4. Options - The options you would like to use to assist with the functionality you want. In this case you want to move the files and exclude the batch file so you will be listing two options.

Re: can I have a script in same folder as where merging from

Posted: 04 Aug 2018 13:50
by tweacle
Please correct me if im wrong but this is the way I understand ROBOCOPY as was posted it would be no good to me as

1) im trying create a subfolder with a question asking if it a BTP or CHILTERN download

Code: Select all

rem Ask if BTP download to determine 
set Download=
choice /C YN /M "Is this a BTP download (Y/N)?"
if !ERRORLEVEL! EQU 1 (
  set Download=BTP
) else (
  choice /C YN /M "IS THIS A CHILTERN DOWNLOAD(Y/N)?"
  if !ERRORLEVEL! EQU 1 (
    set Download=CHILTERN
  )
2) Then asks me for a specific number

Code: Select all

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
Once ive input the number it makes a sub folder

Code: Select all

rem Make a subfolder for the reference number
md "%BaseDir%\%Download%%RefNum%"
Thats when the problem occours as it merges the .BAT script too.

Therefore the robocopy would be copying from X:/downloads to X:/downloads creating a subfolder and ignoring inserting the .bat file but it DOES NOT ask me to input a reference number and ask me if it a chiltern or BTP download of which is extremely important or do I just use the script as far as insert reference number and create a subfolder using robocopy? but will it take the data from the rest of the script?

Reason for this is that overnight this script runs and moves everything

Code: Select all

@echo off
set Source=X:\DOWNLOADS
set Target=X:\DOWNLOADS1
for /F %%a in ('dir  /od /b "%Source%\btp*.*"') do set Folder=%%a
xcopy /y "%SourcE%\%Folder%"  "%Target%"
set Source=X:\DOWNLOADS
set Target=X:\DOWNLOADS2
for /F %%a in ('dir  /od /b "%Source%\chiltern*.*"') do set Folder=%%a
xcopy /y "%SourcE%\%Folder%"  "%Target%"
del /q "X:\DOWNLOADS\*"
FOR /D %%p IN ("X:\DOWNLOADS\*.*") DO rmdir "%%p" /s /q
xcopy X:\DOWNLOADS2 X:\DOWNLOADS3 /E 

Re: can I have a script in same folder as where merging from

Posted: 04 Aug 2018 14:27
by Squashman
Reread my original statement.
Squashman wrote:
03 Aug 2018 13:47
Instead of using the MOVE command, use ROBOCOPY and use the exclude file and move options that ROBOCOPY has.
What does this mean to you? Did I say you had to change anything else in your script besides the MOVE command?

Re: can I have a script in same folder as where merging from

Posted: 04 Aug 2018 15:11
by tweacle
No but its sorted now anyway so thanks

Re: can I have a script in same folder as where merging from

Posted: 04 Aug 2018 18:04
by Squashman
tweacle wrote:
04 Aug 2018 15:11
No but its sorted now anyway so thanks
Yes. I see you have been posting the same sob story on multiple forums(SS64, Computer Hope, VBForums, etc...) across the Internet for several months now using one of your aliases (Tweacle, Daffied, Shreked, glennm). If you would have spent this much effort actually learning to program batch files and vbscript instead of making multiple account across multiple forums you would be pretty fluent in one of these scripting languages by now.