Windows 10: Forfiles "del @file" using wrong path for delete

Discus and support Forfiles "del @file" using wrong path for delete in Windows 10 Gaming to solve the problem; I have a batch using forfiles command to regularly delete old files.forfiles /p C:\A\B\C\D\E\ /s /m *.abc /d -10 /c "cmd /c del @file"It works well so... Discussion in 'Windows 10 Gaming' started by Shitironman, Oct 15, 2024.

  1. Forfiles "del @file" using wrong path for delete


    I have a batch using forfiles command to regularly delete old files.forfiles /p C:\A\B\C\D\E\ /s /m *.abc /d -10 /c "cmd /c del @file"It works well so far on 5 PCs WIN7 and WIN10, but on one also Win7 doing it wrong:Finds the file, so echo @path is C:\A\B\C\D\E\file1.abc is goodthen it tries to delete from one folder up C:\A\B\C\D\file1.abc for some reason. Not a surprise, it will fail as cannot find file.Do you have any idea what could be the issue with this one particular PC? Could be some evil windows setting?Note: Del @path seemingly does the job, b

    :)
     
    Shitironman, Oct 15, 2024
    #1
  2. qphan Win User

    Forfiles Error Invalid Agrument

    Not sure why return error Invalid Agrument

    Some one can see the issue. Thank you.

    forfiles /p C:\Program Files\MicrosoftSQLServer\MSSQL15.SQL\MSSQL\Backup\ -s -m *.bak /D -2 /C "cmd /c del /q @path"
     
    qphan, Oct 15, 2024
    #2
  3. Delete Files with Task Scheduler using ForFiles

    Why are you searching subdirectories when you plan on clobbering everything with "rd /s /q"?

    What you might (are probably) be seeing is this:

    1. forfiles builds a list of files to work with:
      say... "C:\This" and "C:\This\That"
    2. You get "C:\This" handed to you
    3. You delete "C:\This" recursively
    4. You get "C:\This\That" handed to you.
    5. You get an error deleting it because it doesn't exist.

    One other condition can happen too! There can be a file handle open while enumerating the tree so when you try to delete "C:\This", "C:\This\That" is still locked open by forfiles. I don't know if forfiles is written to circumvent this but I have for sure run into this while programming.

    Suggestion: Drop the /S from forfiles (best) OR add "blah blah blah.. if exist @file" blah blah blah (not best).
     
    Señor CMasMas, Oct 15, 2024
    #3
  4. n0tiert Win User

    Forfiles "del @file" using wrong path for delete

    Batch file

    this is more shorter, the other where to reach the goal

    Code: @Echo OFF REM Set File Path variable SET SPLFILES=%WINDIR%\SYSTEM32\spool\printers\ REM Build Menu :MENU CLS ECHO ............................................... ECHO. ECHO 1 - Open *.spl Files ECHO 2 - Clear Spooler cache ECHO 3 - EXIT ECHO. ECHO ............................................... ECHO. SET /P M=Type 1, 2, or 3 then press ENTER: IF %M%==1 GOTO SPL IF %M%==2 GOTO CLEAR IF %M%==3 GOTO EOF REM check if there are any and open files with notepad :SPL REM "FORFILES" Native command in Vista/Windows7/2008, via Resource Kit for XP for %%G in (.spl) do FORFILES -p %SPLFILES% -m *%%G -c "cmd /c ECHO Opening File: @path & cmd /c notepad @path" ECHO. pause goto MENU REM check if there are any stop spooler , delete files, start spooler :CLEAR net stop spooler ECHO. REM "FORFILES" Native command in Vista/Windows7/2008, via Resource Kit for XP for %%G in (.shd, .spl) do FORFILES -p %SPLFILES% -m *%%G -c "cmd /c ECHO Deleting File: @path & cmd /c del @path /Q" ECHO. net start spooler pause goto MENU REM Exit Script :EOF exit[/quote] have fun
     
    n0tiert, Oct 15, 2024
    #4
Thema:

Forfiles "del @file" using wrong path for delete

Loading...
  1. Forfiles "del @file" using wrong path for delete - Similar Threads - Forfiles del @file

  2. Forfiles "del @file" using wrong path for delete

    in Windows 10 Software and Apps
    Forfiles "del @file" using wrong path for delete: I have a batch using forfiles command to regularly delete old files.forfiles /p C:\A\B\C\D\E\ /s /m *.abc /d -10 /c "cmd /c del @file"It works well so far on 5 PCs WIN7 and WIN10, but on one also Win7 doing it wrong:Finds the file, so echo @path is C:\A\B\C\D\E\file1.abc is...
  3. C# Project File Uses Wrong Paths

    in Windows 10 Gaming
    C# Project File Uses Wrong Paths: In VS 2022 I am trying to create a C# Winforms project file that contains the references I frequently use ad links to files I regularly use.My base project directory is D:\Data\Visual Studio 2022\ProjectsWhen I create a new project based on the template the path of the linked...
  4. C# Project File Uses Wrong Paths

    in Windows 10 Software and Apps
    C# Project File Uses Wrong Paths: In VS 2022 I am trying to create a C# Winforms project file that contains the references I frequently use ad links to files I regularly use.My base project directory is D:\Data\Visual Studio 2022\ProjectsWhen I create a new project based on the template the path of the linked...
  5. Windows uses file paths the wrong way

    in Windows 10 Software and Apps
    Windows uses file paths the wrong way: When typing filepaths into, for example, the windows explorer, it automatically messes up the path by replacing the slashes with backward slashes. The same applies to many other applications, like the command prompt. Where can I disable this behavior?...
  6. Windows uses file paths the wrong way

    in Windows 10 Gaming
    Windows uses file paths the wrong way: When typing filepaths into, for example, the windows explorer, it automatically messes up the path by replacing the slashes with backward slashes. The same applies to many other applications, like the command prompt. Where can I disable this behavior?...
  7. Help using Forfiles command

    in Windows 10 Network and Sharing
    Help using Forfiles command: Hello everyone, I am having a syntax error when executing my forfiles command. My proposal is to develop a .bat script to everyday copy the last file backup from a folder to the one drive folder located in another drive "K" This is the command I am using forfiles...
  8. Forfiles error

    in Windows 10 Customization
    Forfiles error: I am running Windows 10 and upon startup I am getting a notification titled C:\WINDOWS\system32\forfiles.EXE...sometimes it loads Errors and other times it remains blank. My computer performance does not seem to be impacted. Can anyone advise?...
  9. can't delete files in the wrong place

    in Windows 10 Support
    can't delete files in the wrong place: two files have appeared inside my lifelock program and i can't delete them. other ways to delete than using the delete button? ETA: sorry. the program is folderlock. 68303
  10. DOS CMDs - For and Forfiles to rename files

    in Windows 10 Support
    DOS CMDs - For and Forfiles to rename files: I have just bought a Surface 4 Pro with k'brd. I find that one old program will no longer run correctly, so need to make a Batch file to replace it. Windows 10 screen capture produces files all with the same name, appending a serial number. Capture.exe produces a .bmp...