简体   繁体   中英

How to print part of the line in a text file using batch file commands

-rwx------ root;SQL_ root;Doma      393216 Jul 05 05:00 V:\MSSQL\Backup\mydb\mydb_backup_2020_07_05_050000_9821955.trn
-rwx------ root;SQL_ root;Doma      393216 Jul 05 06:00 V:\MSSQL\Backup\mydb\mydb_backup_2020_07_05_060001_9241754.trn
-rwx------ root;SQL_ root;Doma      393216 Jul 05 07:00 V:\MSSQL\Backup\mydb\mydb_backup_2020_07_05_070001_7545780.trn
-rwx------ root;SQL_ root;Doma      393216 Jul 05 08:00 V:\MSSQL\Backup\mydb\mydb_backup_2020_07_05_080001_4850750.trn
-rwx------ root;SQL_ root;Doma      393216 Jul 05 09:00 V:\MSSQL\Backup\mydb\mydb_backup_2020_07_05_090001_3588313.trn
-rwx------ root;SQL_ root;Doma      393216 Jul 05 10:00 V:\MSSQL\Backup\mydb\mydb_backup_2020_07_05_100001_2038178.trn
-rwx------ root;SQL_ root;Doma      393216 Jul 05 11:00 V:\MSSQL\Backup\mydb\mydb_backup_2020_07_05_110000_9809957.trn

these details are in a text file and I want only the file names like V:\MSSQL\Backup\mydb\mydb_backup_2020_07_05_050000_9821955.trn and pass it to delete command.

I used this command in a batch file

FOR /F %%i IN (<file location>) DO del /Q %%i.

However it fails as it reads the 1st line and has special characters -rwx----- .

Thanks, this command helped me:

FOR /F "tokens=8 delims= " %a IN (<file_name> or <file_path>) do del %a

Ex: as a command:

FOR /F "tokens=8 delims= " %a IN (N:\Test_Folder\DELETE-FILES-20200709_195526) do del %a

in a batch file:

FOR /F "tokens=8 delims= " %%a IN (N:\Test_Folder\DELETE-FILES-20200709_195526) do del %%a

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM