I have a batch file that opens a URL to download a csv file, then I need to move and then rename that csv form downloads folder to other one.
What I have is:
#echo off
SET CCDIR=C:\Users\(username)\Desktop
SET LOADDIR=C:\Users\(username)\Downloads
ECHO ***************************************************************************
ECHO Downloading the file
ECHO ***************************************************************************
start chrome (URL string)
:NEXT
ECHO ***************************************************************************
ECHO Move CSV file from Downloads folder to Desktop
ECHO ***************************************************************************
move %LOADDIR%\*(file string)* %CCDIR%
ren %CCDIR%\*(file string)* (new file name)
I want to execute it all in the same bat, but just the start chrome is working, the bat is ignoring the move and ren.
How can I do that?
Based on my comment, you can give a try for this example to download a file with Certuil command
#echo off
Title Downloading a file using Certutil Command
Mode 70,5 & color 0A
SET CCDIR=%userprofile%\Desktop
SET LOADDIR=%userprofile%\Downloads
set "url=https://download.sysinternals.com/files/PSTools.zip"
echo(
ECHO ******************************************************************
ECHO Please wait a while ... Downloading the file ...
ECHO ******************************************************************
Call :download %url% %LOADDIR%
Rem Moving the downloaded file from the folder Downloads to Desktop
move /Y "%file%" "%CCDIR%\">nul
Rem Open the desktop folder with explorer
Explorer "%CCDIR%\"
goto :eof
::--------------------------------------------
:Download <Url> <File>
Set url="%~1"
Set file=%2\%~nx1
certutil.exe -urlcache -split -f %url% %file%>nul
Rem Deleting cache
certutil -urlcache "%~1" delete>nul
Rem Check referenced urlcache is deleted
certutil.exe -v -urlcache -split "%~1">nul
exit /b
::--------------------------------------------
Related
I inherited a set of batch files.
Bat1 called bat2 which called bat3.
Bat3 created an xml, which bat2 used to create an html and bat1 used that to create a pdf.
Finally bat1 copied the pdf to an output directory.
I've recently joined the three batch files into one and everything works exactly the same up to the final copy command, which fails stating the pdf cannot be found.
#echo off
pushd %~dp0
set sourceFile=%1
set xslt=%2
set outputFile=%3
for %%i in (%sourceFile%) do (
set documentName=%%~ni
)
::BATCH FILE 2 CALLED
::BATCH FILE 3 CALLED
echo Processing source file compose
java -cp lib\saxon9.jar; net.sf.saxon.Transform -s:%sourceFile% -xsl:conversion\compose.xsl -o:compose.xml
echo Processing source file catalog
java -cp lib\saxon9.jar; -s:compose.xml -xsl:conversion\catalog.xsl -o:catalog.xml
::END OF BATCH FILE 3
echo Processing source file to HTML
java -cp lib\saxon9.jar; net.sf.saxon.Transform -s:catalog.xml -xsl:conversion\html5.xsl -o:index.html
echo Bundling publication
mkdir %documentName%
xcopy /y "conversion\webapp\*" %documentName%\ /o /x /e /h /k
move index.html %documentName%\
copy source graphics into web application img res dir
for %%f in ("*.jpg" "*.png" "*.gif" "*.svg" "*.psd" "*.ai" "*.pdf") do copy "%%f" %documentName%\asset\img\
::END OF BATCH FILE 2
echo Running AHF
AHFCmd -extlevel 4 -d %documentName%\index.html -o %documentName%.pdf -f HTML -x 4 -i tool\AHF\AHFSettings(x64).xml -stdout
::EVERYTHING WORKS FINE TO HERE; %documentName%.pdf is created just as it was previously.
echo Moving %documentName%.pdf
copy %documentName%.pdf %outputFile% ::Error - The system cannot find the file specified.
popd
The line copy %documentName%.pdf %outputFile% hasn't changed. I have tried using CALL in front of the AHFCmd and JAVA commands but that makes no difference. I have tried dir /b /a-d just before the copy command and it lists the file I want to move in the current directory. What am I doing wrong?
I Made A Batch File Which Would Open In Notepad++ From The CURRENT DIRECTORY where the batch file is located(with run.. feature in notepad++), But I Want batch file to open on the folder where i have opened the file.
Example:
My Batch File Is Located In D:\Projects\Java\Executor Java.bat
I Have Opened A File Of .java Extension in D:\Java\Files
I Want to open at file location,i.e. D:\Java\Files
My batch file Looks like this:
#ECHO OFF
ECHO WELCOME TO EXECUTOR
ECHO -Garvit Joshi(garvitjoshi9#gmail.com)
ECHO USER:%USERNAME%
cd /d "%~dp0"
:first
ECHO LOOKING FOR FILES IN:"%~dp0"
set /p "input=Enter The File You Want To Execute:"
ECHO ===============================
javac %input%.java
ECHO ===============================
set /p "input=Enter The Class You Want To Run:"
ECHO ===============================
ECHO OUTPUT:
ECHO ===============================
java %input%
ECHO ===============================
pause
ECHO =======================================================
ECHO *******************************************************
ECHO =======================================================
goto first
You'll need to pass the path as a parameter from Notepad++ in the 'Run...' dialog, e.g:
cmd /c "D:\Projects\Java\ExecutorJava.bat $(CURRENT_DIRECTORY)"
..then have your batch file use the parameter with something like:
cd /d "%1"
(In this example, have removed the space from the "Executor Java.bat" filename for convenience)
I'm moving a task from manual to automatic
I'm well aware that you can't check for errors when doing this, but that's not my goal.
My code works as expected, but I'm missing... something
I need to let the user know that after I've put the file in the FTP location, that it was uploaded and they no longer need to wait for the file.
I've done this up to now by blagging the user, once the command has run, they just get told it's worked
#echo off
REM Generates the script
echo open 000.000.000.000> temp.txt
echo username>> temp.txt
echo password>> temp.txt
echo lcd "N:\line\line\line">> temp.txt
echo put file.txt>> temp.txt
echo quit>> temp.txt
REM Open FTP and run the script above
ftp -s:temp.txt
REM Remove the temp file
del temp.txt
REM Display confirmation
msg %username% "File sent to FTP"
Any help is greatly appreciated. I will add any more info if needed
You have to download the file back to see if it was correctly uploaded and do fc.
For unattened file download via ftp look at robvanderwoude's ftp. Don't forget that when saving the downloaded file it should have different name than the one you were uploading originally.
Then simply compare the files you have via fc command like this:
#echo off
fc c:\temp.txt r:\temp_to_check.txt > nul
if errorlevel 1 goto error
goto :EOF
:error
echo "The file was uploaded and downloaded incorrectly"
Answer specific to my question for visual purposes:
REM Open FTP and run the script above
ftp -s:temp.txt
REM File check
fc "N:\line\line\TEST.TXT" "N:\line\line\check_location\TEST.TXT" > nul
if errorlevel 1 goto error
REM Remove the temp file
del temp.txt
REM Display confirmation
msg %username% "File has now been sent to FTP"
goto :EOF
:error
msg "The file was uploaded or downloaded incorrectly"
Hello i was trying to download a .rar archive on mediafire but it doesnt seem to work it the file doesnt get to the specific folder
"c:\potato"
Here is my code:
#Echo off
echo download press any key
pause
bitsadmin.exe /transfer "JobName"
http://download1142.mediafire.com/sxd533x3fosg/ymr5y2r0yax2fx8/minecraft+generator.zip C:\Potato.exe
pause
Try something like this:
#echo off
setlocal EnableDelayedExpansion
set "infile=http://download1142.mediafire.com/3b1mz9yb72tg/ymr5y2r0yax2fx8/minecraft+generator.zip"
set "outfile=Potato.zip"
cd "C:\"
echo download press any key
pause
powershell.exe -Command (new-object System.Net.WebClient).DownloadFile('"%infile%"','"%outfile%"') | findstr "Exception error" >nul 2>nul
set "downloadComplete=%errorlevel%"
if %downloadComplete% neq 1 echo Something went wrong, please try again
if %downloadComplete% neq 1 pause
if %downloadComplete% neq 1 goto :eof
unzip "%outfile%" "minecraft generator.zip" >nul
unzip "minecraft generator.zip" "minecraft generator.exe" >nul
rename "minecraft generator.exe" "potato.exe"
pause
Please note that you used the mediafire URL instead of the actual file URL, and that you try to download a zip file to .exe. You should first download the file as zip, and then use unzip to unzip the files.
Also note that your second zip seems to be password protected.
I am trying to create a batch file that gets a zipped folder for that particular date (v_date) from the sftp site and then unzip them. The zip file contains five files that are text documents. I have written batch scripts that successfully get the zip file from the remote site and save a copy of it on the local drive. I need to incorporate the unzip part in to my script.
SET v_date=%1
if [%v_date%] == [] SET v_date=%date:~10,4%%date:~4,2%%date:~7,2%
echo option batch continue>FTP_File_Get.txt
echo option confirm off>>FTP_File_Get.txt
echo open Target>>FTP_File_Get.txt
echo lcd "M:\Development\Data History\File" >> FTP_File_Get.txt
echo cd /Export/File >> FTP_File_Get.txt
echo get /Export/File/Filename_%v_date%.zip "M:\Development\DataHistory\Filename_%v_date%.zip">>FTP_File_Get.txt
echo exit>>FTP_File_Get.txt
M:\temp\apps\WinSCP\winscp.com/script="M:\Development\SFTPBatchFiles\FTP_File_Get.txt"
del FTP_File_Get.txt
This is my code to UNZIP:
SET v_date=%1
if [%v_date%] == [] SET v_date=%date:~10,4%%date:~4,2%%date:~7,2%
cd "M:\Development\Data History\"
::SET v_file="M:\Development\Data History\Filename_%v_date%.zip"
::unzip -o %v_file%
"C:\Program Files\7-Zip\7z.exe" e "Filename_%v_date%.zip"
I need to move the extracted files (6 Files) into their respective folders, Any help is greatly appreciated
To unzip the files you can use this command line:
"C:\Program Files\7-Zip\7z.exe" e "filename.zip"
#echo off
set "source=%userprofile%\Desktop\basanta\Automation\a"
set "target=%userprofile%\Desktop\basanta\Automation\b"
FOR %%A IN ("%source%\*.gz") DO (
"%programfiles%\7-zip\7z.exe" x "%%~A" -o"%target%\%%~pA"
del "%%~A" /Y
)
Use the above code by saving it to .bat file extension
Remember %userprofile% is for the directory, %programfiles% for the program files set as a variable in windows
hope that helps