1

I am new to using windows command prompt so apologies if this is a simple question. I am using forfiles to produce a list of all files within a folder and its subdirectories, with this list also including the files last date and time modified. This works correctly but for some files the list will print a ~$ within the files name even though the actual file name does not include this. For example the command returns:

ExampleFolder1\ExampleFolder2\~$Examplefilename.docx 10/10/2010 10:10

when it should return

ExampleFolder1\ExampleFolder2\Examplefilename.docx 10/10/2010 10:10

This only happens for some of the files within the printed list.

Additionally, sometimes the file with the ~$ printed when forfiles is run is the name of a file that does not actually exist in the folder and on some occasions it appears to be a copy of a file that has already been printed when forfiles is ran but the time modified shall differ. For example forfiles may return:

ExampleFolder1\ExampleFolder2\Examplefilename.docx 10/10/2010 10:10
ExampleFolder1\ExampleFolder2\~$Examplefilename.docx 11/11/2010 20:10

I was just wondering if anyone else had come across this issue?

The only theory I had is maybe its returning ~$ file names for files that have been deleted or cut and moved elsewhere, but I have limited knowledge in command prompt so i'm not sure at all.

Here is the code I have been using to print a list all files and subdirectory files for a folder (excluding directories):

FORFILES /s /c "cmd /c if @isdir==FALSE echo @path @fdate @fdate"

Ideally I would just like to know the reason for why such files are being printed. Thanks for any help

4
  • I just ran the exact same command (except I added the closing double quote) in a folder containing 41 subdirectories and several hundred files, and didn't see a single instance of what you describe. I then ran it again and redirected the output to a text file so I could more closely inspect the results, and again can't find a single instance of ~$ at the start of a filename, even using the Find functionality in Notepad++. As the examples you describe both have a .docx extension, I'd suspect that those are Word backup files and that they actually do exist on your system.
    – Ken White
    May 24, 2019 at 17:23
  • Also, if you look at the examples you provided, the two filenames are identical if you remove the ~$, but have different date and time stamps, also typical of a Word backup file.
    – Ken White
    May 24, 2019 at 17:25
  • Thanks for the quick response, I've edited the question so it contains the closing double quote I missed when typing the code out for the question. Thats a good explanation as it does seem to be only on a small minority of office files with extensions such as .xlsx and .docx where this is occuring. Thanks for the help
    – Beckford10
    May 24, 2019 at 17:45
  • if you're new then do yourself a favor and use PowerShell instead
    – phuclv
    May 25, 2019 at 2:09

1 Answer 1

2

Microsoft Office files containing ~$ in the filename are called "owner" files. These files are part of Office's file locking mechanism and contain the account name of the user that has the file open. These files are generally hidden as "operating system files" and are sometimes left behind if the Office application doesn't close properly.

This is how Microsoft Office applications can show you this message:

File In Use dialog

You can display these files in Windows Explorer by:

  1. Windows 7:

    1. Clicking Organize
    2. Clicking Folder and search options

    Windows 10:

    1. Clicking File
    2. Clicking Change folder and search options
  2. Opening the Folder Options dialog

  3. Clicking the View tab
  4. Selecting "Show hidden files, folders and drives"
  5. Unchecking "Hide protected operating system files (Recommended)"

Folder Options dialog

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.