forfiles

At which point does `forfiles` enumerate a directory (tree)?

蓝咒 提交于 2020-01-04 23:31:35
问题 The command forfiles is intended to enumerate a directory and apply (a) certain command(s) on each item. With the /S the same can be accomplished for a full directory tree. What happens when the content of the enumerated directory (tree) is changed by the command(s) in the body of the forfiles command? Supposed we have the directory D:\data with the following content: file1.txt file2.txt file3.txt The output of forfiles /P "D:\data" /M "*.txt" /C "cmd /C echo @file" when executed in said

How to tell forfiles to execute command in PATH?

自作多情 提交于 2020-01-02 02:34:06
问题 I'm missing something (obvious?) about escaping my strings or spaces in the following Windows Server 2k3 batch command. FORFILES -m *.wsp -c "CMD /C C:\Program^ Files\Common^ Files\Microsoft^ Shared\web^ server^ extensions\12\bin\stsadm.exe^ -o^ addsolution^ -filename^ @FILE" Results in the following error 'C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm.exe -o addsolution -filename "foobar.wsp"' is not recognized as an internal or external command,operable

How to nest two `forfiles` loops properly (so that the inner body expands variables of both iteration levels)?

删除回忆录丶 提交于 2019-12-08 15:04:32
问题 I am trying to nest two forfiles loops so that the command of the inner loop receives @ variables from both the outer and the inner loop iteration. For the latter the @ variable replacement needs to be escaped for the outer loop so that the inner forfiles command receives the variable name. I have got a code snippet that enumerates a given directory ( C:\root ), and if the iterated item is a directory on its own, all the contained text files ( *.txt ) are listed. However, it does not work as

Forfiles - spaces in folder path

≡放荡痞女 提交于 2019-12-07 20:57:13
问题 I am running a batch file and I have one forfiles command in it FORFILES -p%spinputarchrootpath% -m*.csv -d-365 -c"CMD /C DEL @FILE" %spinputarchrootpath% variable maps to a folder location (Y:\Temp Documents\testfolder). Now the above command is throwing an error because of the space in the folder name (Temp Documents). How to handle this space? I have tried putting quotes around %spinputarchrootpath% variable but it is not working. 回答1: Enclose the path in quotes: FORFILES -p "

Forfiles - spaces in folder path

岁酱吖の 提交于 2019-12-06 13:43:56
I am running a batch file and I have one forfiles command in it FORFILES -p%spinputarchrootpath% -m*.csv -d-365 -c"CMD /C DEL @FILE" %spinputarchrootpath% variable maps to a folder location (Y:\Temp Documents\testfolder). Now the above command is throwing an error because of the space in the folder name (Temp Documents). How to handle this space? I have tried putting quotes around %spinputarchrootpath% variable but it is not working. Enclose the path in quotes: FORFILES -p "%spinputarchrootpath%" -m *.csv -d -365 -c "CMD /C DEL @FILE" Note, there's a space between -p and "%spinputarchrootpath%

How to use forfiles (or similar) to delete files older than n days, but always leaving most recent n

耗尽温柔 提交于 2019-12-05 07:28:09
问题 (Using Windows 2000 and 2003 Server) We use forfiles.exe to delete backup .zip files older than n days, and it works great (command is a bit like below) forfiles -p"C:\Backup" -m"*.zip" -c"cmd /c if @ISDIR==FALSE del \"@PATH\@FILE\"" -d-5 If a .zip file fails to be created, I'd like to ensure that we don't end up with 0 .zip files in the backup after 5 days. Therefore, the command needs to be: "delete anything older than 5 days, but ALWAYS keep the most recent 5 files, EVEN if they themselves

Forfiles Batch Script (Escaping @ character)

情到浓时终转凉″ 提交于 2019-11-29 01:24:08
I'm working on a batch script that will let me delete files older then a set period using forfiles . For now, I'm aiming at printing the files that will be deleted. The forfiles invocation I'm using works flawlessly from a cmd.exe shell, but as soon as I embed it into a batch script, it barfs. I suspect that this is due to the @ character not being escaped properly, but I'm not certain. The command I'm running is: forfiles /S /P "r:\" /m *.bak /d -10 /c "cmd /c echo @PATH" And it results in the following error: ERROR: Invalid argument/option - '@PATH' Type "FORFILES /?" for usage. I've googled

forfiles with UNC path

▼魔方 西西 提交于 2019-11-28 23:21:58
I am trying to use forfiles to delete files that are older than 7 days. The files are in a UNC path. Below is the script that I am using. Forfiles -p \\devexpress\C$\FULL\ -s -m *.* -d -7 -c "cmd /c del /q @path" But I get an error mentioning that UNC paths (\machine\share) are not supported. There appears to be workarounds available but cannot get a clear answer googling. PA. The error I get when trying to reproduce the problem says that the problem is not with FORFILES not suporting UNC Path, but with CMD not being able to start with an UNC path as default directory. In case that this is

Forfiles Batch Script (Escaping @ character)

与世无争的帅哥 提交于 2019-11-27 21:36:33
问题 I'm working on a batch script that will let me delete files older then a set period using forfiles. For now, I'm aiming at printing the files that will be deleted. The forfiles invocation I'm using works flawlessly from a cmd.exe shell, but as soon as I embed it into a batch script, it barfs. I suspect that this is due to the @ character not being escaped properly, but I'm not certain. The command I'm running is: forfiles /S /P "r:\" /m *.bak /d -10 /c "cmd /c echo @PATH" And it results in

forfiles with UNC path

瘦欲@ 提交于 2019-11-27 14:54:48
问题 I am trying to use forfiles to delete files that are older than 7 days. The files are in a UNC path. Below is the script that I am using. Forfiles -p \\devexpress\C$\FULL\ -s -m *.* -d -7 -c "cmd /c del /q @path" But I get an error mentioning that UNC paths (\machine\share) are not supported. There appears to be workarounds available but cannot get a clear answer googling. 回答1: The error I get when trying to reproduce the problem says that the problem is not with FORFILES not suporting UNC