topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday December 10, 2024, 2:43 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Change File Name. Then change it back to what it was.  (Read 5320 times)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Change File Name. Then change it back to what it was.
« on: February 25, 2022, 04:47 PM »
Vic (and community), I used to put small requests in Skwire's section.  Haven't for a while.  I have a mini request presently that probably belongs over there.  But will just put it here for now....

Change File Name.  Then change it back to what it was.

This would be a two-phase process:

A file is in a folder.  Alone.  File is:  "4863 - xyz.txt"

Step #1.  Change that file's name to:  "xyz.txt"

(User now does some things.  Blah, blah....)

Step #2.  Change the file "xyz.txt" back to its original name, "4863 - xyz.txt"

Done!

If there is another forum where this request is more appropriate, please let me know.  Or if there is a means that I ought to have access to (some programming language?).

Thanks a million.  Hope all are well.

Nicholas Kormanik


BGM

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 563
    • View Profile
    • bgmCoder DC
    • Read more about this member.
    • Donate to Member
Re: Change File Name. Then change it back to what it was.
« Reply #1 on: February 25, 2022, 08:38 PM »
Well, what if you just copied the file and changed the extension to ".bak" or something?  Then, when you want it back, just change the extension back from bak.

Or, you could log what files you open. 

What is a case scenario where you would want to only temporarily name something and keep ahold of the old name?

publicdomain

  • Moderator
  • Joined in 2019
  • *****
  • Posts: 736
  • Call me Vic!
    • View Profile
    • Donate to Member
Re: Change File Name. Then change it back to what it was.
« Reply #2 on: February 25, 2022, 08:52 PM »
Change File Name.  Then change it back to what it was.

Hi Nick, I'm in with nkNameFlip @ https://github.com/p...licdomain/nknameflip

As to the section, if you post it here rest assured there's no problem on my side.

Hey! GitHub motto says it: current goal is 52+ releases per year, so I'm glad to do it :) Your creative ideas do help others around :Thmbsup: Thanks for following your passion & publishing them.



Regarding naming:

Is the format "number - filename.ext" all the time?

Do you need a split by hyphen or any other character as an option?

Feel free to elaborate on the naming format.

Cheers!
My name's Victor but do feel free to call me Vic! (now known as "paradisusvic")

❤️ Support on Patreon @ www.patreon.com/paradisusis
New Email/Paypal: paradisusvicgmail.com

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: Change File Name. Then change it back to what it was.
« Reply #3 on: February 26, 2022, 12:43 AM »
@BGM , @publicdomain and helpful community.

BGM, your idea is a good one.  Copy out, then copy back in.  Or rename.  Etc.

Trouble is, the file contents will change.

Here is the actual scenario:

I have 100 SAS datasets.  Each dataset is alone in its folder.  The folder name corresponds to the dataset filename, plus some extra:

Below are the first three folders, and the sole file inside:

===========
E:\00\AAPL\
===========
aapl_combined.sas7bdat

===========
E:\00\ACWI\
===========
acwi_combined.sas7bdat

===========
E:\00\ACWX\
===========
acwx_combined.sas7bdat

I need to update -- add some additional columns -- to each and every dataset file.

The 'program' -- or more accurately, 'script' -- I am going to use to make the changes to each file expects the name of the file to be:

combined.sas7bdat

No prefix.

And the location of said file is set to be:

C:\SAS_1\

So, it appears that I'll have to use one of the two following approaches:

(first dragging each respective file one at a time to the 'work' folder for the running of the script)

1.  Change the 'script' file 100 times, to tailor for the specific prefix.

or

2.  Change the name of each file, temporarily.  x100.

Going #2 route, I was thinking of TEMPORARILY changing the filename:

aapl_combined.sas7bdat --> combined.sas7bdat

Then making changes to the dataset file with the existing script.

Then changing the filename back to what it was before:

combined.sas7bdat --> aapl_combined.sas7bdat

Then dragging the changed dataset file back to its proper, home folder.

This whole rigmarole is likely faced regularly by programmers.  There surely are ways and means of conducting things more efficiently.  If anyone wants to chime in their thoughts regarding a more orderly process, please speak up.

Thanks much!

Nicholas Kormanik


Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: Change File Name. Then change it back to what it was.
« Reply #4 on: February 26, 2022, 02:56 AM »
Just a suggestion, but wouldn't it be much more efficient to improve the 'script' to handle any filename? This workaround seems so inefficient, and prone to bite you in the behind, sometime soon.

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: Change File Name. Then change it back to what it was.
« Reply #5 on: February 26, 2022, 04:14 AM »
Good suggestion @Ath.  Unfortunately I don't see that SAS will allow ambiguity with the dataset it's acting on.

Here's partial code:

proc summary data=sas_1.combined;
var
i_50501_Z
i_50502_Z
i_50503_Z
i_50504_Z
i_50505_Z
i_50508_Z
;
output out=sas_1.combined_temp (drop= _:) p80= /autoname;
run;

The .combined part refers to the dataset being acted upon.  I don't believe I can use a wildcard there.

I would need to change dataset filenames.  Or change script.


nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: Change File Name. Then change it back to what it was.
« Reply #6 on: February 26, 2022, 04:20 AM »
Seriously, you folks need to deal with shenanigans and efficiently organizing projects all the time.  Otherwise, your butts would be full of bites.

To my knowledge, all that effort and skill never gets talked about.


Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: Change File Name. Then change it back to what it was.
« Reply #7 on: February 26, 2022, 10:13 AM »
I'm pretty sure you can rework that SAS script to accept a filename in a variable (never used or interpreted SAS script, but did a quick google search on it), so executing the script while passing the filename(s) should be really doable.
This is only to avoid getting stuck with a 'one trick pony' tool ;D
And adjusting the script will improve someone's skills, if not yours :P

publicdomain

  • Moderator
  • Joined in 2019
  • *****
  • Posts: 736
  • Call me Vic!
    • View Profile
    • Donate to Member
Re: Change File Name. Then change it back to what it was.
« Reply #8 on: February 26, 2022, 10:26 AM »
Hi Nick, please confirm this the procedure you want coded for "Route #2":

List all subfolders inside "E:\00\":

E:\00\*

For each subdirectory copy each sole file to "C:\SAS_1\", using fixed name:

E:\00\AAPL\aapl_combined.sas7bdat → C:\SAS_1\combined.sas7bdat

Run external script.

After script finishes, copy the resulting file back:

C:\SAS_1\combined.sas7bdat → E:\00\AAPL\aapl_combined.sas7bdat

Repeat until all listed subfolders are processed.



The solutions above are "proper" yet as I'm amid closing the month of releases, this straightforward proggie is okay. Some times you just want the quick solution! If that's the case, a traditional .exe with GUI from me.

Please confirm :)

Cheers!
My name's Victor but do feel free to call me Vic! (now known as "paradisusvic")

❤️ Support on Patreon @ www.patreon.com/paradisusis
New Email/Paypal: paradisusvicgmail.com
« Last Edit: February 26, 2022, 10:33 AM by publicdomain »

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: Change File Name. Then change it back to what it was.
« Reply #9 on: February 26, 2022, 05:04 PM »
I'm pretty sure you can rework that SAS script to accept a filename in a variable (never used or interpreted SAS script, but did a quick google search on it), so executing the script while passing the filename(s) should be really doable.
This is only to avoid getting stuck with a 'one trick pony' tool ;D
And adjusting the script will improve someone's skills, if not yours :P

You are exactly right, @Ath.  My life as a complete amateur in programming is 'one trick pony.'  Move along day to day here at the computer until some hurdle comes up, and then attempt to find the solution to get over that hurdle.

I suppose that's one of the main differences between non-programmers and programmers.  You folks build a large steady base, and have and know a plethora of tools, and versatility to use them appropriately.

You are indeed correct that there exist tools in SAS to accomplish passing filenames.  I've been having a discussion regarding this on the SAS forums.  Hate wasting your time, but here's the link:


Macro code to iterate through list


nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: Change File Name. Then change it back to what it was.
« Reply #10 on: February 27, 2022, 06:55 PM »
Change File Name.  Then change it back to what it was.

Hi Nick, I'm in with nkNameFlip @ https://github.com/p...licdomain/nknameflip

nkNameFlip is all that's desired presently, Victor.  Thanks!

Such function might be useful for others, too.  Changing a filename.  And then later changing it back to what it was.  Seems like a reasonable tool to have on hand.

I'm curious if anyone out there has come across an easy way to do this.  If so, please speak up.



publicdomain

  • Moderator
  • Joined in 2019
  • *****
  • Posts: 736
  • Call me Vic!
    • View Profile
    • Donate to Member
Re: Change File Name. Then change it back to what it was.
« Reply #11 on: February 27, 2022, 07:35 PM »
nkNameFlip is all that's desired presently, Victor.  Thanks!

Thanks for your confirmation. I proceed to code it :up:

Cheers!
My name's Victor but do feel free to call me Vic! (now known as "paradisusvic")

❤️ Support on Patreon @ www.patreon.com/paradisusis
New Email/Paypal: paradisusvicgmail.com