I'm using the following code to delete all instances of Acad.lsp found on my C:\ drive but I want to make one exception, which is C:\Autocad 2010\Support.
How can I achieve this?
del "C:\ICT\acad.lsp" /q /a /s
From a command line you could use the batch file for command (I'm assuming that you're using a Windows command prompt or similar here). This is a powerful command that will let you loop through a set of "things" - with the right options, these "things" may be files.
The following command, when run in the C:\ICT directory, should do what you want:
for /F "usebackq" %a in (`dir /s /b acad.lsp ^| find /v "C:\Autocad 2010\Support"`) do #echo %a
Note that I'm using #echo here so that you can test that the results are as you expect before you change the #echo to del.
If you wanted to put this into a batch file, you should change %a to %%a.
A little explanation on what's happening:
for /F "usebackq" %a in (...) runs the command that is between the back-quotes, and runs the command following the do on each item that results. The command in my example above does a recursive dir for the file acad.lsp, and puts that through the find command to remove the one you want to keep. The remaining files are the ones that you will want to delete.
Related
I need to close all windows of a specific Chrome profile. Suppose I execute:
chrome.exe -remote-debugging-port=4000 --user-data-dir=F://chrome
in cmd/bat to open a new Chrome profile. I need to close this specific Chrome profile from cmd/bat.
I have tried this:
taskkill /IM chrome.exe -remote-debugging-port=4000 --user-data-dir=F://chrome
but it's not working.
You can accomplish this using the batch file below:
for /f "tokens=3 delims=," %%a in ('wmic process where "caption='chrome.exe'" get processID^,commandline /format:csv ^| FIND "-remote-debugging-port=4000 --user-data-dir=F://chrome"') do set _pid=%%a
taskkill /f /pid %_pid% /t
Explanation
wmic process where "caption='chrome.exe'" get processID^,commandline /format:csv lists all chrome.exe processes with the command line used to launch them and the process ID that we will use to kill it.
Piping (|) this into FIND "-remote-debugging-port=4000 --user-data-dir=F://chrome" will return only the chrome.exe process started with the command you used.
for /f "tokens=3 delims=," %%a in ("...") do set _pid=%%a will set the _pid environment variable to the process ID of the process we want to kill.
The wmic command combined with the find command should only give us a single result. If you used the command multiple times, then this will only find the process ID of the last process in the list.
taskkill /f /pid %_pid% /t:
/f forces the task to end, because otherwise Chrome will remain open.
/pid %_pid% will supply the process ID we got in the for loop.
/t tells taskkill to kill the entire process tree.
Since every Chrome tab and extension runs in its own process, we want to make sure these get killed as well.
I've got 300 .csv files. I need to add a column that contains the filename in each row. I'm new to using command line in terminal. I've looked around but haven't found code I understand for doing this in mac. Would be very grateful for help
You could write a bash-script:
vi csv-script.sh
press i (for inserting text)
copy/paste this code as example (is kind of self-explaining):
#!/bin/bash
for file in $(find ./ -maxdepth 1 -name '*.csv' -type f)
do
touch tmp
for line in $(cat $file)
do
fileCol="${file:3}"
echo "${fileCol};${line}" >>tmp
done
mv -f tmp $file
rm -f tmp
done
change the semicolon within the echo-command to whatever separator you need.
press esc and press colon :wq
then call from cli with:. csv-script.sh. (pay attention to dot space csv-script.sh)
have a try.
Need help on this.
I would like to make my general_log file for mysql from single huge file into a daily log file.
I created a batch file to rename and create anew general log file,
but it still write into the renamed file.
Are there a config in mysql or am I missing a command here, so that the general log will not write on the renamed file / or just create a new general log / or will just write to the new empty file? thanks in advance
btw, batch file is below:
#echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set
dt=%%a
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%
set stamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%
ren C:\wamp\logs\generalmysql.log "generalmysql - %stamp%.log"
#echo off
echo.>"C:\wamp\logs\generalmysql.log"
Screenshot
solved my issue by flushing the logs
call "C:\wamp\bin\mysql\mysql5.7.14\bin\mysqladmin.exe" -u'root' -h localhost flush-logs
I tried to execute the command with open command also
set command "C:\Program Files(x86)\gs\bin\gswin32c.exe -sDEVICE=pdfwrite -o $createpdfpath D:/test/1/ghostscript/gs9.19/lib/viewjpeg.ps -c \"($Modifiedjpgpath) <</PageSize 2 index viewJPEGgetsize 2 array astore >> setpagedevice viewJPEG\""
set f [open "$command" "r"]
After execution i am getting the below error:
couldn't open "C:\Program Files(x86)\gs\bin\gswin32c.exe -sDEVICE=pdfwrite -o C:/sample/Et/Alpha_10H00000001.0.00000102.00000001/23.pdf D:/test/1/ghostscript/gs9.19/lib/viewjpeg.ps -c "(\\\\Test-PC\\TRAIL-P\\Ds\\PS\\0\\17\\Color_00000001.jpg) > setpagedevice viewJPEG"": no such file or directory
But if i am executing the same command via command prompt it is converting the jpg to pdf file without any error.
Unless your Windows setup is different from the run of the mill, then "C:\Program Files(x86)" is incorrect, and should be "C:\Program Files (x86)", note the missing space in your definition.
So something like :
set command "C:\Program Files (x86)\gs\bin\gswin32c.exe........"
FWIW Ghostscript doesn't normally install into that directory either, I would expect the directory to be of the form "c:\Program Files (x86)\gs\gsX.YY\bin\gswin32c" where X.YY is the Ghostscript version number.
The main problem you've got is that you're not running that command as a pipeline.
You need to change:
set f [open "$command" "r"]
to:
set f [open |$command "r"]
You may also have typos in your pipeline descriptor, which I recommend you build as a list, and file nativename is probably important as well, not so much for the name of the ghostscript interpreter itself, but rather for any filenames that are given to it:
# Easiest to use / instead of \ in filenames inside Tcl, really
set gs "C:/Program Files (x86)/gs/bin/gswin32c.exe"
set psscript "D:/test/1/ghostscript/gs9.19/lib/viewjpeg.ps"
# The next bit is building some postscript to run
set thejpgfile [file nativename $Modifiedjpgpath]
set pscmd "($thejpgfile) <</PageSize 2 index viewJPEGgetsize 2 array astore >> setpagedevice viewJPEG"
# Compose everything into a subprocess invokation
set command [list $gs -sDEVICE=pdfwrite -o $createpdfpath [file nativename $psscript] -c $pscmd]
# Actually run it
set f [open |$command "r"]
I find it is usually simpler to try to keep lines of code shorter and use variables to give individual bits a helpful name. It's also a lot easier to debug; you can just print out anything that looks too mysterious.
I use the following .bat script
set varSearch="C:\Users\User1\Desktop\Test-folder\*.crypt8"
for /f %%i in ('dir %varSearch% /B ') do set varSearch= %%i
WhatsAppViewer.exe -decrypt8 %myName% key exp.db
sqlite3.exe exp.db<command.txt
cd C:\xampp\mysql\bin
mysql -u admin -p1234 < query.txt
The basic function is to find a file thats ending with .crypt8, decrypt it, save as csv and import to mysql. Its working correctly
But i need some extra features
Case1
The folder contains more than 1 file, and every file has to be processed, but only once
Case 2
Everyday at least one file gets added. It would be superb if the .bat could be scheduled as a task, and run every night and just process the new added files.
Does anybody has a solution for this?
Case 2
The forfiles command processes groups of files based on date. This does files made today only.
forfiles /d 0 /m *.crypt8 /c "cmd /c echo #fname in #path"
Case 1
Your code has errors, it may work but not under all conditions.
The easist way is to put the sequence of commands in a batchfile for a file (%1) which is passed on command line, and use forfiles to call it.