create batch script file with user prompt and xcopy - batch-file

I'm trying to create a batch script file to help an administrative assistant in my work group. Let's call him John.
John receives many CDs daily from clients containing architectural drawings as PDFs. Each CD is unique. John assigns it an Application Number, and creates a new folder on the network drive with the Application Number as the folder name. John then copies all the files on the CD to the newly created folder name. He repeats this process for every CD he receives.
I don't have any programming experience so I hope you can lend me a hand. Here's what I wrote below but it's not working. I get an "Insufficient memory" error. A new folder name based on the user input is correctly created on the network drive path but it's empty.
Thanks for your help! FYI, I'm running Windows 7 64-bit
#echo off
echo Welcome team member!
pause
set /p anumber=Type in the Application Number then press Enter key when done.
mkdir "S:\ARCH\Active Forms and Files\Submittal Floor Plans\%anumber%\"
:: e:\ is the CD drive path
set source=e:\
:: S:\ is a network drive
set destination="S:\ARCH\Active Forms and Files\Submittal Floor Plans\%anumber%\"
xcopy %source%\* %destination%\* /s /e /l /h /i >nul
pause
exit

You were setting the variable %source% to e:\ which was the read by the interpreter as E:\\* when used in %source%\*, leading to an invalid directory. The same was being done to the %destination% variable.
Updated Script:
#echo off
set "networkFolder=S:\ARCH\Active Forms and Files\Submittal Floor Plans"
set "CDDrive=e:"
echo Welcome team member!
:input
set "applicationNo="
set /p "applicationNo=Enter the Application Number and press ENTER: "
if not defined applicationNo goto :input
set "newLocation=%networkFolder%\%applicationNo%"
:actions
md "%newLocation%"
xcopy %CDDrive%\* "%newLocation%" /s /e /i /h>nul
echo Completed!
pause

Related

Batch Script to copy folder from Server to user desktop in a network

My goal is to create a batch script to copy a folder with subfolders to user desktop with overwrite option and minimized of command prompt.
I am pushing the script through Group policy in user start up screen.
However I am getting an error when running the script locally. Not sure what I am missing in the script..
#echo off
#cls
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
echo Your Source Path:
set INPUT1=\\X.X.X.X\Test\TMS\
echo Your Destination Path:
set INPUT2=C:\Users\%Username%\Desktop\
xcopy %INPUT1% %INPUT2% /y /s
:minimized
You mentioned folder, so I am writing this assuming you want to create the TMS folder with content on the desktop.
I would try something like this inside of you minimized label. This is untested as I have no Network drives to test with.
for /f "tokens=2" %i in ('net use * "\\X.X.X.X\Test\TMS\" ^| findstr /i Drive') do set "tmpDr=%%i"
mkdir "%USERPROFILE%\Desktop\TMS" >nul
xcopy "%tmpDir%\*" "%USERPROFILE%\Desktop\TMS" /s /y
net use /d %tmpDir% >nul
Some things to note in your code. You have 2 minimized labels, you need to enclose path variables with double quotes to eliminate possible whitespace, you can drop the echo's seeing as you plan on running the script minimized. Last but not least, you do not need to specify full path to the user's desktop as %USERPROFILE% variable already exists as Drive:\Users\Username

Shutdown script via GPO displays unwanted window

Created a GPO to run a batch file on shutdown for domain XP computers - with the purpose of deleting old user profiles.
For this I am using an application called DeleteProfiles from OptimumX.
cd C:\
if exist "Program Files (x86)" GOTO Exit (Checks if XP or not)
if exist DeleteProfiles GOTO COMMAND
:CopyDeleteProfiles
md DeleteProfiles
copy /Y \\SomeShare\SomeFolder\DeleteProfiles\DeleteProfiles.exe
C:\DeleteProfiles\
:COMMAND
pushd C:\DeleteProfiles\
start /Wait DeleteProfiles.exe /MIN:14 /Y
rem (/Min: # = Delete profiles older than # and /y removes yes or no prompts)
:Exit
End
It works alright, but a CMD window appears at shutdown with the output of the program.
How do I make it go away?
The real problem here is that users can close the program which causes the script to stop. If I can't make that go away, I would like at least to make the window not close-able.
Looked up start /?, adding the /b parameter does the job
start /b /Wait DeleteProfiles.exe /MIN:14 /Y

How to take user input and insert it into a copy directory process in a Batch file?

I am trying to cut the time it takes to set up Autodesk for the employees at work. To do this I needed to first map a network drive and then copy a couple of files from the network drive to Autodesk on the users C drive. However, since each PC will be different because it goes into the user profile; I had to make a input variable to take in the name.
This is what I have:
#echo Create new K: drive mapping
#net use K: \\vasalacad\autocad\library
#echo Enter User ID "firstname.lastname"
#set /p UserID=""
#copy /y "K:\setups\tmco1.dwt" "C:\Users\"UserID"\AppData\Local\Autodesk\AutoCAD Electrical 2015\R20.0\enu\Template"
#copy /y "K:\setups\BlackPlot.ctb" "C:\Users\"UserID"\AppData\Roaming\Autodesk\AutoCAD Electrical 2015\R20.0\enu\Plotters\Plot Styles"
:exit
#pause
What I got was this:
Create new K: drive mapping
The command completed successfully.
Enter User ID "firstname.lastname"
******.*******
The system cannot find the path specified.
0 file(s) copied.
The system cannot find the path specified.
0 file(s) copied.
Press any key to continue . . .
I edited the user input so that I wouldn't display the name on the forums. Any help would be much appreciated. Thanks in advance.
Use your env variable properly using %:
#copy /y "K:\setups\tmco1.dwt" "C:\Users\%UserID%\AppData\Local\Autodesk\AutoCAD Electrical 2015\R20.0\enu\Template"
#copy /y "K:\setups\BlackPlot.ctb" "C:\Users\%UserID%\AppData\Roaming\Autodesk\AutoCAD Electrical 2015\R20.0\enu\Plotters\Plot Styles"
Alternately, you could provide the script to your users, and in that case, no interactions, and they would do (no need to mount a drive BTW):
#copy /y "\\vasalacad\autocad\library\setups\tmco1.dwt" "%USERPROFILE%\AppData\Local\Autodesk\AutoCAD Electrical 2015\R20.0\enu\Template"
#copy /y "\\vasalacad\autocad\library\setups\BlackPlot.ctb" "%USERPROFILE%\AppData\Roaming\Autodesk\AutoCAD Electrical 2015\R20.0\enu\Plotters\Plot Styles"
OR: create a text file (here users.txt) containing 1 user per line and copy the files in a loop:
#echo off
set SRC=\\vasalacad\autocad\library\setups
for /F %%a in (users.txt) do (copy /y "%SRC%\tmco1.dwt" "C:\Users\%%a\AppData\Local\Autodesk\AutoCAD Electrical 2015\R20.0\enu\Template"
copy /y "%SRC%\BlackPlot.ctb" "C:\Users\%%a\AppData\Roaming\Autodesk\AutoCAD Electrical 2015\R20.0\enu\Plotters\Plot Styles"
)

SIMPLE :: XCOPY NOT PRODUCING OUTPUT IN .bat

I'm a mortgage loan guy in Seattle, WA and I frequently set up a folder hierarchy into which I save a client's documents and as they come in to me. I've been creating these manually for years and I'd like to save the 3 to 4 minutes it takes to set these up by using a batch file.
So... I have a default set of folders, some of which contain a couple of small Adobe PDFs. What I'd like to do (and cannot make happen) is to run a batch file that would facilitate some custom remarks or input from me during the batch so that with a click and a couple of keystrokes, I have an organized folder setup for a new client within seconds rather than minutes.
I've written the following but it isn't producing any output folders or files.
______not sure character terms show correctly - see linked images below for actual______
#echo off
::Ask
echo Your Source Path:
set INPUT1=
set /P INPUT1=Type input:
echo Your Destination Path:
set INPUT2=
set /P INPUT2=Type input:
C:\WINDOWS\system32\xcopy.exe /e /v %INPUT1% %INPUT2%
My responses were:
to the first prompt "E:\DV8333 MY DOCUMENTS\002 ATLAS\ATLAS RESOURCES\000NEWCLIENTFOLDER2014"
to the second prompt "E:\DV8333 MY DOCUMENTS\001 CLIENTS\"
I have verified that xcopy.exe is in fact located as indicated above.
I'm on XP SP3
My actual paths and .bat file are shown in the linked image for clarity.
http://www.avidrecording.com/images/01.png
Thanks in advance, much appreciated.
#Rem save this as a .bat file and run
#echo off
set /P source=Enter Source Folder:
echo %Source%
set /P destination=Enter Destination Folder:
echo %destination%
xcopy %source% %destination% /v /i /e
Fundamentally, your problem appears to be that the xcopy command can't figure out which of the data it is receiving is parameters and which switches and which superfluous because you have spaces in your directorynames.
Fortunately, the cure is simple. "quote your parameters"
C:\WINDOWS\system32\xcopy.exe /e /v "%INPUT1%" "%INPUT2%"
Now - the path to xcopy.exe is probably superfluous - as is the extension, so
xcopy /e /v "%INPUT1%" "%INPUT2%"
is more than likely all you'd need.
(I'd caution to experiment with a throw-away destination until you've perfected your method. I use a RAMDISK...)
Also, if you're copying a template, then there's no apparent reason for all the folderol about inputting Input1. If you have more than one template set, set up a separate batch and shortcut for each one with a fixed template path, eg
xcopy /e /v "E:\DV8333 MY DOCUMENTS\002 ATLAS\ATLAS RESOURCES\000NEWCLIENTFOLDER2014" "%INPUT2%"
Note the use of quotes to defeat the evil spaces.
Next, your destination could be built, but may contain spaces. For instance, you may have a client to which you wish to refer as "037 - Fred Nurk". Now it's a pain to have to type in the full path, so make it easy. Just type in the 037 - Fred Nurk part and let batch fill in the rest.
xcopy /e /v "E:\DV8333 MY DOCUMENTS\002 ATLAS\ATLAS RESOURCES\000NEWCLIENTFOLDER2014" "E:\DV8333 MY DOCUMENTS\001 CLIENTS"\"%input2%"\
Note that this will append the input as a directory under E...001 clients. Note that the strings are concatenated and the double-quotes are there solely to tell batch "here be a string that may contain spaces."
If this works, and there's no reason why it wouldn't (does for me...) then all you'd need to do is enter the client details and the template would be copied to a new directory. Now actually playing around with the data in the files that are copied so that they are customised - well, at the price, that would be worthy of another question...
#echo off
echo Backing up file
set /P source=Enter source folder:
set /P destination=Enter Destination folder:
set /P Folder name=Enter Folder name
set xcopy=xcopy // Set the switches as per your need
%xcopy% %source% %destination%
pause

Batch file to delete temp files on a remote workstation

I wrote an easy batch to basically ask me a server name and then it would go and delete the temp files out of the specified directories. Yes I know power shell would probably be way more effective but Im still pretty new to my Sysadmin position and the network is so large Im not ready to be mingling in that area yet.
But anyway I would love to be able to create a list of the servers and have it go through them all deleting these temp files instead of opening a new command window for each server and then executing my batch file. I either want to have the list of servers already in the batch file or have the batch call back to .txt file with the server list and then open a brand new cmd prompt window for each server and commence the deletion.
Here is what I have so far, Its simple, its easy, it works, but Im coming across imputing about 100 servers so that's about 6 command prompt windows at a time (to avoid confusion) letting them go through and delete and when they all finish open another 6 give them all another server then let them delete and ETC
:deleteit
echo off
echo ------------------------------------------------------
set /p server=Please enter the name of your workstation/server you wish to clean:
echo You have entered %server% as your workstation
pause
del "\\%server%\c$\temp\*.*" /s /f /q
del "\\%server%\c$\windows\temp\*.*" /s /f /q
del "\\%server%\c$\windows\ProPatches\Patches\*.*" /s /f /q
rd /s "\\%server%\c$\$Recycle.bin"
echo --------------------------------------------------
set /p choice=Again? (y/n)
if /i %choice%==Y (goto deleteit) else (goto end)
:end

Resources