Jump to content

stuck on @comspec quotes or the autoit code


Recommended Posts

(example) search a folder -----( 10 files  ) and keep the newest 5      (or a set number)  and then deletes the rest

i did come across a fair few post on '' deleting by x amount of days '' rather than the way i am trying    (also seems a lot of code compared the cmd way )

i do like to do it the Autoit way       as i learn far more each time ..

also i would still like to learn how to get the quotes right as that can become usefull like breaking parts below into more $var's keeping the quotes correctly

the code i would use in cmd.

set BPATH= "Folder Location"

for /f "skip=5 delims=" %%F in ('dir % BPATH%\*.bk /s/b/o-d/a-d') do del "%%F"

i know i could have made another Variable to set file type (*.bk).... witch i will later

anyway i gave up trying to do it the autoit way witch i guess would be (file get time) and a loop to repeat checking the folder

i tried

$BPATH = 'path of folder'
Run(@ComSpec & ' /k ' & 'for /f "skip=5 delims=" %%F in ('dir %BPATH%\*.bk /s/b/o-d/a-d') do del "%%F ', @SW_SHOW)

iv only picked option to show as see it working before hide and maybe ass error support to it

i know i can use fileinstall and run the bat file from my program but again this way is cheating and i am not learning witch will improve my future coding

 

hopefully my English is understandable lol

 

 

Link to comment
Share on other sites

  • Developers

Maybe something like:

$BPATH = 'path of folder'
Run(@ComSpec & ' /k for /f "skip=5 delims=" %%F in (''dir ' & $BPATH & '\*.bk /s/b/o-d/a-d'') do del "%%F" ', @SW_SHOW)

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers
3 minutes ago, larksp said:

cmd pops up and disappears so i don't have time to see what the error was

Just figure out what the proper command is to run on the CMD prompt by running it there and post it here incase it doesn't work when ran with AutoIt3.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

after the Edited 17 minutes ago by Jos  does not popup with cmd at all now....

 

this works fine i did post it in the top post

save code as test.bat

make a folder in C:\bkk

make new text,txt rename to blar.bk copy past 10 times for example

then run

set BACKUPPATH= "C:\bkk"

for /f "skip=5 delims=" %%F in ('dir %BACKUPPATH%\*.bk /s/b/o-d/a-d') do del "%%F"

 

results
C:\Users\******>set BACKUPPATH
= "C:\bkk"

C:\Users\******>for /F "skip=5
 delims=" %F in ('dir "C:\bkk"\*.bk /s/b/o-d/a-d') do del "%F"

C:\Users\*******>del "C:\bkk\t.
bk"
Press any key to continue . . .

 

 

 

 

Link to comment
Share on other sites

  • Developers

That is running a batch file, which is also possible, but does it work when typing the command on the CMD prompt as that is what you are trying to do in AutoIt3?

You can of course also create the Batch file with your AutoIt3 script which then runs it and deletes the file again.

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

thank you for pointing that out.. it reminded me of out post about command coding where if ran for a bat you have to do this

(     %%F   )

and in cmd only %f

 

iwhile doing code like ( for /F "skip=5 delims="  ) if its wrong cmd does not say open

25 minutes ago, JLogan3o13 said:

It should not disappear if you're using ' /k instead of ' /c

 

 

anyway thanks i will try that and post back

Link to comment
Share on other sites

thank you       Jos      

that worked it kept 5 and removes the rest... see how the quotes and and are used to remember for the future

another time maybe nice to know how to do it with out CMD and do it the autoit way

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...