batch-file

How to batch-copy the 10 newest files to a directory in Windows?

戏子无情 提交于 2020-01-10 06:12:07
问题 I use the following script to keep only the newest 360 files (a year, daily-made backup) in the directory: for /f "skip=360 eol=: delims=" %%F in ('dir /b /o-d /a-d *.*') do @del "%%F" How to afterwards copy the newest 7 files to another directory? 回答1: @echo off setlocal enableextensions disabledelayedexpansion rem Three alternatives rem Pure arithmetics set "numFiles=7" for /f "delims=" %%a in ('dir /b /o-d /a-d') do ( 2>nul set /a "1/numFiles", "numFiles-=!!numFiles" && ( echo copy "%%~fa"

How to batch-copy the 10 newest files to a directory in Windows?

不问归期 提交于 2020-01-10 06:11:11
问题 I use the following script to keep only the newest 360 files (a year, daily-made backup) in the directory: for /f "skip=360 eol=: delims=" %%F in ('dir /b /o-d /a-d *.*') do @del "%%F" How to afterwards copy the newest 7 files to another directory? 回答1: @echo off setlocal enableextensions disabledelayedexpansion rem Three alternatives rem Pure arithmetics set "numFiles=7" for /f "delims=" %%a in ('dir /b /o-d /a-d') do ( 2>nul set /a "1/numFiles", "numFiles-=!!numFiles" && ( echo copy "%%~fa"

How to write an XML tag with double quotes using command prompt echo command

落爺英雄遲暮 提交于 2020-01-10 05:25:08
问题 Good afternoon, I would like to add the simpliest tag into a file, using a CMD batchfile, but it seems that the double quotes are spoiling the party: From other StackOverflow posts I am aware of the double quote state machine and the usage of ^" (^ as an escape character). Still I can't make it work: Hereby my attempts (with their results): C:\>echo <tag variable="value"> // very naïve The syntax of the command is incorrect. C:\>echo "<tag variable="value">" // let's use quotes for delimiting

Echo batch file arrays using a variable for the index?

天大地大妈咪最大 提交于 2020-01-10 05:15:06
问题 If I have a batch file and I am setting arrays with an index that is a variable @echo off SET x=1 SET myVar[%x%]=happy How do I echo that to get "happy" ? I've tried ECHO %myVar[%x%]% ECHO %%myVar[%x%]%% ECHO myVar[%x%] But none of them work. It works fine if I use the actual number for the index ECHO %myVar[1]% But not if the index number is also a variable 回答1: SET x=1 SET myVar[%x%]=happy call echo %%myvar[%x%]%% set myvar[%x%] for /f "tokens=2* delims==" %%v in ('set myvar[%x%]') do @echo

WinSCP “Too many parameters for command 'open'.” error

女生的网名这么多〃 提交于 2020-01-10 04:39:13
问题 I am trying to connect to an SFTP with the following command to move all .csv files from one location to another and I'm getting the "Too many parameters for command 'open'." error. option echo off option batch on option confirm off open sftp://XXX@XXX.com/ —hostkey="ssh-rsa 2048 XX:XX:XX:XX:XX:XX:XX" —rawsettings ProxyMethod=3 ProxyHost=proxy.uk.XXX.com cd /XX/XX/XX/IN/LOAD lcd \\XX.local\EMEA\XX\XX\Import_Location put *.csv -nopreservetime=on -nopermissions=on exit I added the —hostkey

Batch Convert TXT to XLS Using VBA

穿精又带淫゛_ 提交于 2020-01-10 04:30:17
问题 I am trying to convert a directory full of .txt files to .xls using VBA. I am using the following code: Sub TXTconvertXLS() 'Variables Dim wb As Workbook Dim strFile As String Dim strDir As String 'Directories strDir = "\\xx\xx\xx\xx\Desktop\Test\Test1\" strFile = Dir(strDir & "*.txt") 'Loop Do While strFile <> "" Set wb = Workbooks.Open(strDir & strFile) With wb .SaveAs Replace(wb.FullName, ".txt", ".xls"), 50 .Close True End With Set wb = Nothing Loop End Sub The issue is: when I run it, it

Batch file to download a file with name that starts with a given string from FTP

…衆ロ難τιáo~ 提交于 2020-01-10 03:17:46
问题 I use the following bat file: ::@echo off cd /d %0\.. set cmd=%CD% echo user %~2> %cmd%\ftpcmd.dat echo %~3>> %cmd%\ftpcmd.dat echo bin>> %cmd%\ftpcmd.dat IF NOT "%5" == "" echo cd %~5>> %cmd%\ftpcmd.dat echo get %~4 %cmd%\%~4>> %cmd%\ftpcmd.dat echo quit>> %cmd%\ftpcmd.dat ftp -n -s:%cmd%\ftpcmd.dat %1 del %cmd%\ftpcmd.dat Parameters and executions are like below: c:\download.bat ftpHost login password file.xml FTP_FOLDER As you can see this script copy file with the specific name. How can I

How does this Windows batch file run embedded javascript?

冷暖自知 提交于 2020-01-10 03:07:06
问题 How does Windows know that this is JSCRIPT? @set @junk=1 /* @echo off cscript //nologo //E:jscript %0 %* goto :eof */ x = WScript.Arguments Yr = x(0) ; Mo = x(1) YS = "JanFebMarAprMayJunJulAugSepOctNovDec" MN = Mo<1 || Mo>12 ? Mo : YS.substr(3*Mo-3, 3) // Month Name WScript.echo(" ", Yr, " ", MN) WScript.echo(" Mo Tu We Th Fr Sa Su") WD = new Date(Yr, Mo-1, 1).getDay() ; if (WD==0) WD = 7 // Week Day Number of 1st LD = new Date(Yr, Mo, 0).getDate() // Last Day of month Wk = "" ; for (D=1 ; D

Windows Batch Variable within variable

孤者浪人 提交于 2020-01-09 11:27:05
问题 In windows batch could you set a variable within a variable? Explained: So the %num% is within the variable. set num=5 set cnum=test set h1=%c%num%% Is it possible to make the percents work like parenthesis? The output should be h1=test Any help would be appreciated. 回答1: Your example in your question is a mess, but I think I understand what you are looking for: @echo off setlocal set C1=apple set C2=orange set C3=banana set num=2 :: Inefficient way without delayed expansion :: This will be

Use a variable in a 'for' loop

◇◆丶佛笑我妖孽 提交于 2020-01-09 11:24:54
问题 I have following code: @echo off SET ITER=0 for %%i in (%*) do ( SET ITER+=1 ECHO %ITER% ) The output is (for three arguments): 0 0 0 Expected output: 1 2 3 Why can't I access the updated variable in the for loop? 回答1: Expansion of variables with percents is done before a statement/block is executed. So in your case the complete block is expanded before the echo %ITER% is executed, to constant echo 0 . The variable ITER itself is updated in the loop properly. To avoid this, you could use the