New to making batch files some help would be awesome.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
peonowns
Posts: 15
Joined: 29 Apr 2014 03:30

Re: New to making batch files some help would be awesome.

#16 Post by peonowns » 13 May 2014 05:04

Can only say thanks again,
When I tried to do it myself it put all 3 folders into the sub folder with 100 101 etc but looking at how you have coded it i can see where i went wrong ! :!: :D
Will let you know how i get on.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: New to making batch files some help would be awesome.

#17 Post by foxidrive » 13 May 2014 05:11

Bewdy. Good to hear you're getting into it.

peonowns
Posts: 15
Joined: 29 Apr 2014 03:30

Re: New to making batch files some help would be awesome.

#18 Post by peonowns » 13 May 2014 05:37

Seems to be working in all tests I have done!
Just going to double check a lot of the folders to ensure everything is transferred and intact, then i will make a quick backup just encase and do a final test on the live environment to ensure it still works when the paths are across the network rather than local.
Can't see a problem as I have the appropriate permissions.

peonowns
Posts: 15
Joined: 29 Apr 2014 03:30

Re: New to making batch files some help would be awesome.

#19 Post by peonowns » 13 May 2014 07:41

I have added a way to try and stop accidental usage not sure if it is the best way.
I suppose a better way would be with commands for user input?

Code: Select all

@echo off
echo You're about to run the Archive and create batchfile!
pause

echo Please check to make sure no one is using the archive folder!

pause

pushd "C:\Testbegin" || goto :EOF
for /f "skip=10 delims=" %%a in ('dir *-* /b /o-n /ad') do (
    robocopy "%%a" "C:\Testend\%%a" /move /e
)

pause

for /f "tokens=2 delims=-" %%a in ('dir *-* /b /on /ad') do set /a start=%%a + 1
set /a end=start + 49
for /L %%a in (%start%,1,%end%) do (
                  md "%start%-%end%\%%a"
                  md "%start%-%end%\%%a\cads"
                  md "%start%-%end%\%%a\production"
                  md "%start%-%end%\%%a\purchasing"
)
popd

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: New to making batch files some help would be awesome.

#20 Post by foxidrive » 13 May 2014 07:50

peonowns wrote:I have added a way to try and stop accidental usage not sure if it is the best way.
I suppose a better way would be with commands for user input?

Code: Select all

@echo off
echo You're about to run the Archive and create batchfile!
pause

echo Please check to make sure no one is using the archive folder!

pause


This puts a bit more onus on the user as they have to be proactive to make it run.


Code: Select all

@echo off
echo You're about to run the batchfile to Archive and create folders...
echo.
echo Please check to make sure no one is using the archive folder!
set "var="
set /p "var=type GO and press enter when you have done that: "
if not "%var%"=="GO" goto :EOF

peonowns
Posts: 15
Joined: 29 Apr 2014 03:30

Re: New to making batch files some help would be awesome.

#21 Post by peonowns » 13 May 2014 07:56

When I use your provided example it shuts the cmd window is there a way to keep it open?

I thought it was echo off

peonowns
Posts: 15
Joined: 29 Apr 2014 03:30

Re: New to making batch files some help would be awesome.

#22 Post by peonowns » 13 May 2014 08:02

Ah it is because i was not entering GO i entered go.

When typing go it closes the window without running.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: New to making batch files some help would be awesome.

#23 Post by foxidrive » 13 May 2014 08:34

It's very specific - the user has to type it as shown - in UPPER CASE.

You can add /i to the following if command if you want any sentence case to work.

peonowns
Posts: 15
Joined: 29 Apr 2014 03:30

Re: New to making batch files some help would be awesome.

#24 Post by peonowns » 04 Jun 2014 04:26

Great thanks for that :)

One problem i am now finding is that the folders are moved to the correct location, but they are not in the parent folder, it seems to "skipped" or deleted.

I edited the locations back to a test location to try and fix but i can't seem to isolate why it is skipping / deleting the parent folder.
I'm about to remove the echos and var type="GO" and re-test

Don't know if you know or can see why this would be happening?

Code: Select all

@echo off
echo You're about to run the batchfile to Archive Quotes...
echo.
echo Please check to make sure no one is using the archive folder!
set "var="
set /p "var=type GO and press enter when you have done that: "
if not "%var%"=="GO" goto :EOF
pushd "C:\Testbegin" || goto :EOF
for /f "skip=10 delims=" %%a in ('dir *-* /b /o-n /ad') do (
    robocopy "%%a" "C:\Testend" /move /e
)


peonowns
Posts: 15
Joined: 29 Apr 2014 03:30

Re: New to making batch files some help would be awesome.

#25 Post by peonowns » 04 Jun 2014 05:36

Think i missed off the %%a will re-edit and test.

Post Reply