BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar

Community Trekker


Apr 21, 2013

removing "~$" in files names



I am writing script to import several Excel files to JMP as follows:



directory = "C:\Documents\Projects\";
Set Default Directory(directory);
allfiles = Files In Directory( directory);
excelfiles = {}
For (i = 1, i<= NI tems(allfiles), i++,
if ( Ends With( allfiles[i], ".xlsx") ,
Insert Into (excelfiles, allfiles[i]);



The problem is allfiles returns { "~$file1.xlsx", "file1.xlsx", "~$file2.xlsx", "file2.xlsx", ...etc}, and I can't seem to get rid of "~$" in the file names. I can't see those files in Windows Explorer, not even when view hidden files is selected. I added !Starts With (allfiles[i], "~$") to the if() statement, it didn't remove those tmp files.


What's more confusing is:

length(excelfiles[1]) = 10

length(excelfiles[2]) = 12


substr(excelfiles[1], 1, 3) = fil ....shouldn't this be "~$f" ??


 I would really appreciate if anyone can shed some light on this. Thanks!



Super User


Jul 25, 2016

Re: removing "~$" in files names

If you do a web search you will find

File with ~$
The ~$myfile.doc file is a temporary file used to help recover data if a program you are using stops unexpectedly. These backup files are commonly created in the same directory that the original file is in and are usually hidden files.Jan 24, 2018
What are the Windows files with tildes? - Computer Hope


This worked for me
directory = "C:\temp\house\";

Set Default Directory( directory );

allfiles = Files In Directory( directory );

excelfiles = {};

For( i = 1, i <= N Items( allfiles ), i++, 
	If( Ends With( allfiles[i], ".xlsx" ) & !Starts With( allfiles[i], "~" ), 
		Insert Into( excelfiles, allfiles[i] );

For( i = 1, i <= N Items( excelfiles ), i++,
	Show( Length( excelfiles[i] ), excelfiles[i] )